Document offline translation method and device, equipment and storage medium
Through the offline document translation method, localized translation is performed using preset chat templates and offline translation models, which solves the problems of data leakage and privacy infringement in online translation tools, and improves the security and user experience of translation.
Patent Information
- Application Number
- CN202411099086.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-12
- Publication Date
- 2024-12-03
AI Technical Summary
Existing online document translation tools have problems such as data leakage, privacy infringement and uncontrollable service, affecting user data security and translation experience.
The offline document translation method is adopted, and by obtaining document data and target language, filling it into a preset chat template, and inputting a pre-installed offline translation model for translation, realizing localized translation, avoiding network transmission, and improving security and controllability.
Document translation can be carried out without the need for the Internet, reducing the risk of information leakage, ensuring the controllability and user experience of translation services, and users can maintain and update translation services by themselves.
Smart Images

Figure CN119067133A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of data processing technology, and in particular to a document offline translation method, device, equipment and storage medium. Background Art
[0002] In daily work, study and life, people always need to read a lot of documents to obtain information and knowledge. However, due to their limited language ability, people often use various tools to translate documents into their native language before browsing. Although there are a lot of document translation tools and services on the Internet, there are often some potential risks in the use of various network tools, such as:
[0003] Data leakage: When uploading documents with sensitive information to online translation platforms, there is a risk that the document content may be stored or accidentally leaked to third parties. Free public translation tools and AI assistants may lack strict data protection measures, resulting in sensitive information being stored on their servers or even publicly available on the Internet. Even if the service provider has a strict data protection policy, if subcontractors or external partners are involved, data may still be exposed to unauthorized third parties during transmission and processing.
[0004] Privacy Intrusion: Online translation services may collect and analyze translated content, which may inadvertently infringe on the privacy of individuals or businesses involved in the document.
[0005] Uncontrollable service: Third-party translation services may update and maintain services without notifying users, and users may lack control over this.
[0006] The potential risks of the above document translation will reduce user data security and affect the user experience of document translation. Summary of the invention
[0007] In order to solve the above technical problems, the present disclosure provides a method, device, equipment and storage medium for offline translation of documents.
[0008] A first aspect of the present disclosure provides a method for offline translation of a document, comprising:
[0009] Acquire document data of a target document and a target language for translation of the target document;
[0010] Fill the document data and the target language into the preset chat template to obtain the target chat template;
[0011] The target chat template is input into a pre-installed target offline translation model, and the document data is translated into the target language based on the target offline translation model to obtain translation data of the document data.
[0012] A second aspect of the present disclosure provides a document offline translation device, comprising:
[0013] A first acquisition module, used to acquire document data of a target document and a target language for translating the target document;
[0014] A filling module is used to fill the document data and the target language into the preset chat template to obtain the target chat template;
[0015] The translation module is used to input the target chat template into a pre-installed target offline translation model, translate the document data into the target language based on the target offline translation model, and obtain the translation data of the document data.
[0016] A third aspect of the present disclosure provides a computer device, comprising:
[0017] A memory and a processor, wherein a computer program is stored in the memory, and when the computer program is executed by the processor, the document offline translation method of the first aspect mentioned above can be implemented.
[0018] A fourth aspect of the present disclosure provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the document offline translation method of the first aspect described above can be implemented.
[0019] Compared with the prior art, the technical solution provided by the present invention has the following advantages:
[0020] The present disclosure obtains the document data of the target document and the target language for the target document translation; fills the document data and the target language into a preset chat template to obtain a target chat template; inputs the target chat template into a pre-installed target offline translation model, and translates the document data into the target language based on the target offline translation model to obtain translation data of the document data. The present disclosure implements document translation through a locally deployed target offline translation model. The target offline translation model is independent of the external network environment and can translate documents without a network. The user's document data will not be directly transmitted to the external network environment to incur the risk of document information leakage. The user can rest assured to use this solution for document translation, which improves the security of document translation. In addition, the local deployment of the large language model can further ensure the controllability of the translation service. The user can maintain and update the application service as needed, which improves the user experience of document translation. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0022] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0023] Figure 1 is a flow chart of a document offline translation method provided by an embodiment of the present disclosure;
[0024] Figure 2 is a flow chart of another document offline translation method provided by an embodiment of the present disclosure;
[0025] Figure 3 is a flow chart of a method for determining a target offline translation model provided by an embodiment of the present disclosure;
[0026] Figure 4 It is a structural schematic diagram of a document offline translation device provided by an embodiment of the present disclosure;
[0027] Figure 5 It is a structural diagram of a computer device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0028] In order to more clearly understand the above-mentioned objectives, features and advantages of the present disclosure, the scheme of the present disclosure will be further described below. It should be noted that the embodiments of the present disclosure and the features in the embodiments can be combined with each other without conflict.
[0029] In the following description, many specific details are set forth to facilitate a full understanding of the present disclosure, but the present disclosure may also be implemented in other ways different from those described herein; it is obvious that the embodiments in the specification are only part of the embodiments of the present disclosure, rather than all of the embodiments.
[0030] It should be understood that the various steps described in the method embodiments of the present disclosure may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this respect.
[0031] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0032] It should be noted that the modifications of "one" and "plurality" mentioned in the present disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0033] The document offline translation method provided by the embodiment of the present disclosure can be executed by a computer device, which can be understood as any device with processing and computing capabilities. The device can include but is not limited to mobile terminals such as smart phones, laptops, personal digital assistants (PDAs), tablet computers (PADs), portable multimedia players (PMPs), vehicle-mounted terminals, wearable devices, etc., as well as fixed electronic devices such as digital TVs, desktop computers, smart home devices, etc.
[0034] In order to better understand the inventive concept of the embodiments of the present disclosure, the technical solutions of the embodiments of the present disclosure are described below in conjunction with exemplary embodiments.
[0035] Figure 1 is a flowchart of a document offline translation method provided by an embodiment of the present disclosure. The method can be executed by a computer device, which can be understood as any device with computing functions and processing capabilities, such as Figure 1 As shown, the method provided in this embodiment includes the following steps:
[0036] Step 110: Obtain document data of the target document and a target language for translation of the target document.
[0037] In the disclosed embodiment, when a user needs to translate a target document into a target language, the target document and the target language into which the target document is translated can be uploaded to a computer device, and the computer device can obtain document data of the target document and the target language into which the target document is translated.
[0038] Document data can be understood as the text data contained in the document.
[0039] The target languages can include Chinese, English, Russian, French and other languages.
[0040] Step 120: Fill the document data and the target language into the preset chat template to obtain the target chat template.
[0041] In the disclosed embodiment, the chat template can be understood as a predefined message template, and the user can fill in the personalized content of the template and send it to the target object. The role of the chat template is to provide services or send notifications. In this way, a better message reading experience can be brought, and the message arrival rate can also be improved. During the chat process, the use of chat templates can help users convey information more effectively, and also make the conversation more structured and organized. In addition, the chat template is also a formatted template for users to interact or communicate with large models. Maintaining the consistency of this format helps optimize the user experience and improve communication efficiency.
[0042] Chat templates can include system messages and user messages.
[0043] System messages may include document translation prompts and translation language prompts. For example, the document translation prompt may be "The model is a professional translator whose task is to translate the document into a specified language and directly output the translation content without additional prompts." The translation language prompt may be the specified language for document translation.
[0044] Role messages can be understood as dynamically inserted translation content placeholders, that is, document data that needs to be translated.
[0045] After obtaining the document data of the target document and the target language of the target document translation, the computer device can fill the document data and the target language into the preset chat template to obtain the target chat template. Specifically, the document data can be filled into the role message of the preset chat template, and the target language can be filled into the translation language prompt in the system message of the preset chat template.
[0046] In some embodiments, before filling the document data and the target language into the preset chat template, the computer device can respond to the user's chat template creation instruction, obtain the system prompts and role prompts corresponding to the chat template from the chat template creation instruction, and the system prompts can include document translation prompts and translation language prompts; fill the system prompts into the system message of the chat template, and fill the role prompts into the role message of the chat template to obtain the preset chat template.
[0047] Specifically, the user can define appropriate prompt prompts, including system prompts and role prompts, in the python file translate.py, and generate chat template creation instructions. The computer device can obtain the system prompts and role prompts corresponding to the chat template from the chat template creation instructions, and then use the ChatPromptTemplate.from_messages method to fill the system prompts into the system messages of the chat template, and fill the role prompts into the role messages of the chat template to obtain the preset chat template.
[0048] For example, a preset chat template could be:
[0049] prompt = ChatPromptTemplate.from_messages[("system","You are a professional translator. I want to translate a document into {targetLanguage}. Each time I will provide you with a section of content to be translated. Note: You only need to output the translated content directly, and do not output any prompts."), ("user","{input}")]).
[0050] ChatPromptTemplate is a core class in the LangChain library that is used to build and format prompt templates for interacting with chat models. It allows users to define a sequence of chat messages in a structured way, with each message associated with content and roles, thereby constructing complex input scenarios for generative language models.
[0051] LangChain is a powerful large language model framework designed to help developers build end-to-end applications using language models. It provides a set of tools, components, and interfaces that simplify the process of creating applications powered by large language models and chat models. LangChain can easily manage interactions with language models, link multiple components together, and integrate additional resources such as APIs and databases.
[0052] Step 130: input the target chat template into a pre-installed target offline translation model, translate the document data into the target language based on the target offline translation model, and obtain translation data of the document data.
[0053] In the disclosed embodiment, a target offline translation model is pre-installed in the computer device, and the target offline translation model can translate the document without being connected to the Internet. For example, the target offline translation model can be a large language model (LLM), Qwen, Llama 3, Gemma, etc.
[0054] After obtaining the target chat template, the computer device may input the target chat template into a pre-installed target offline translation model, translate the document data into the target language based on the target offline translation model, and obtain translation data of the document data.
[0055] The disclosed embodiment obtains the document data of the target document and the target language for the target document translation; fills the document data and the target language into a preset chat template to obtain the target chat template; inputs the target chat template into a pre-installed target offline translation model, and translates the document data into the target language based on the target offline translation model to obtain the translation data of the document data. The disclosed embodiment realizes document translation through a locally deployed target offline translation model. The target offline translation model is independent of the external network environment and can translate documents without a network. The user's document data will not be directly transmitted to the external network environment to incur the risk of document information leakage. The user can rest assured to use this solution for document translation, which improves the security of document translation. In addition, the local deployment of the large language model can further ensure the controllability of the translation service. The user can maintain and update the application service as needed, which improves the user experience of document translation.
[0056] Figure 2 is a flowchart of a document offline translation method provided by an embodiment of the present disclosure. The method can be executed by a computer device, which can be understood as any device with computing functions and processing capabilities, such as Figure 2 As shown, the method provided in this embodiment includes the following steps:
[0057] Step 210: Get the file name of the target document.
[0058] In the embodiment of the present disclosure, the computer device may obtain the file name filename of the target document.
[0059] Step 220: Extract the target document type to which the target document belongs from the file name.
[0060] In the embodiment of the present disclosure, the computer device may extract the target document type to which the target document belongs from the file name of the target document.
[0061] Specifically, the computer device may define a method get_doc_loader in a python file translate.py, and then input a document name filename of a target document to parse out a document type of the target document.
[0062] Document types can include Word, PDF, DOC, TXT, CSV, XML, etc.
[0063] Step 230: Determine a target document loader corresponding to the target document type based on the mapping relationship between the document type and the document loader.
[0064] In the embodiment of the present disclosure, the document loader can be understood as a tool that loads data from various data sources into document objects. The data sources may include local files, the Internet, and various cloud services. The document object can be understood as a combination of a piece of text and related metadata.
[0065] Each document type corresponds to a document loader. For example, the PDF document type corresponds to a PDF document loader (such as PyPDFLoader), the CSV document type corresponds to a CSV document loader (such as CSVLoader), the XML document type corresponds to an XML document loader (such as UnstructuredXMLLoader), the Word document type corresponds to a Word document loader (such as Docx2txtLoader), and the TXT document type corresponds to a TXT document loader (such as TextLoader).
[0066] The computer device pre-stores a mapping relationship between the document type and the document loader. The computer device can determine the target document loader corresponding to the target document type based on the mapping relationship between the document type and the document loader.
[0067] Step 240: Parse the target document based on the target document loader to obtain document data corresponding to the target document.
[0068] In the embodiment of the present disclosure, after determining the target document loader corresponding to the target document type, the computer device may parse the target document based on the target document loader to obtain document data corresponding to the target document.
[0069] Step 250: Obtain the target language for translation of the target document.
[0070] In the embodiment of the present disclosure, the computer device may obtain a target language for translation of a target document input by a user.
[0071] Step 260 , starting from the first character of the document data, the document data is segmented in sequence according to a preset segmentation method to obtain a plurality of text blocks corresponding to the document data.
[0072] In the disclosed embodiment, since the target document loader may have a large amount of document data after parsing the target document, it is impossible to send all of it to the target offline translation model at once. Therefore, it is necessary to segment the document data into multiple text blocks.
[0073] The computer device may start from the first character of the document data and sequentially segment the document data according to a preset segmentation method to obtain multiple text blocks corresponding to the document data.
[0074] The preset segmentation method may include at least one of segmentation by character, segmentation by sentence, segmentation by paragraph and segmentation by page.
[0075] Each text block obtained by character segmentation contains an equal number of characters.
[0076] Each text block obtained by sentence segmentation contains an equal number of sentences.
[0077] Each text block obtained by segmentation contains an equal number of paragraphs.
[0078] Each text block obtained by page segmentation contains an equal number of pages.
[0079] Step 270: sort the multiple text blocks in sequence according to the segmentation order to construct a text block sequence corresponding to the document data.
[0080] In the embodiment of the present disclosure, after obtaining multiple text blocks corresponding to the document data, the computer device can sequentially sort the multiple text blocks according to the segmentation order to construct a text block sequence corresponding to the document data. The text block sequence includes multiple text blocks.
[0081] In some embodiments, any two adjacent text blocks in the aforementioned text block sequence have a preset number of overlapping characters, which helps to maintain the continuity of the context and improve the accuracy of the translation. The preset number can be set as needed and is not limited here.
[0082] Specifically, the computer device can introduce the LangChain segmentation tool dependency in the python file translate.py to complete the parameter initialization configuration of the text segmentation tool. The text segmentation tool can be RecursiveCharacterTextSplitter. For example, configure the number of characters in a single text block, the number of sentences in a single text block, the number of paragraphs in a single text block, the number of pages in a single text block, the number of overlapping characters between adjacent text blocks and other segmentation parameters, and then implement the segmentation of the document data based on the text segmentation tool to obtain multiple text blocks corresponding to the document data, and sort the multiple text blocks in sequence according to the segmentation order to construct a text block sequence corresponding to the document data.
[0083] RecursiveCharacterTextSplitter is a component in the LangChain library for processing and splitting long text data. This tool is specifically designed to support breaking down large documents, articles, or other forms of text content into smaller, more manageable "chunks" or "segments" for subsequent processing, such as vectorization, storage in a vector database, or use by a language model.
[0084] Step 280: For each text block in the text block sequence corresponding to the document data, fill the text block and the target language into the preset chat template to obtain the target chat template corresponding to the text block.
[0085] In an embodiment of the present disclosure, for each text block in a text block sequence corresponding to the document data, the computer device can fill the text block and the target language into a preset chat template to obtain a target chat template corresponding to the text block, and perform this operation on each text block to obtain a target chat template corresponding to each text block.
[0086] Step 290: input the target chat templates corresponding to each text block into a preset target offline translation model in sequence, and translate each text block in the text block sequence into the target language in sequence based on the target offline translation model to obtain translation data of the document data.
[0087] In the disclosed embodiment, the computer device may input the target chat templates corresponding to each text block into a preset target offline translation model in sequence, and translate each text block in the text block sequence into the target language in sequence based on the target offline translation model to obtain translation data of the document data.
[0088] In this way, the document data can be divided into multiple text blocks for document translation, which improves the document translation efficiency and translation accuracy of the target offline translation model. The target offline translation model is independent of the external network environment and can translate documents without a network. The user's document data will not be directly transmitted to the external network environment to incur the risk of document information leakage. Users can safely use this solution for document translation, which improves the security of document translation. In addition, the local deployment of the large language model can further ensure the controllability of the translation service. Users can maintain and update the application service as needed, which improves the user experience of document translation.
[0089] In some embodiments of the present disclosure, before inputting the target chat template into the pre-installed target offline translation model, the computer device may execute Figure 3 A flowchart of a method for determining a target offline translation model is provided, such as Figure 3 As shown, the target offline translation model determination method provided in this embodiment may include the following steps:
[0090] Step 310: In response to a model download instruction from a user, at least one model identifier requested to be downloaded and a download address corresponding to each model identifier are obtained from the model download instruction.
[0091] In an embodiment of the present disclosure, a computer device may receive a model download instruction from a user, and then, in response to the model download instruction from the user, obtain at least one model identifier requested to be downloaded and a download address corresponding to each model identifier from the model download instruction.
[0092] Step 320: For each download address corresponding to the model identifier, download the translation model corresponding to the model identifier from the download address and install it into the local storage space.
[0093] In the disclosed embodiment, for each download address corresponding to the model identifier, the computer device can download the translation model corresponding to the model identifier from the download address and install it into the local storage space. The local storage space is the storage space of the computer device itself.
[0094] For example, the download address can be the URL of the Ollama official website. Ollama is a tool designed for running and customizing large language models in a local environment. It provides a simple and efficient interface for creating, running, and managing these models, as well as a rich library of pre-built models that can be easily integrated into various applications. Ollama's goal is to make the deployment and interaction of large language models simple, both for developers and end users.
[0095] Step 330: Determine the translation model corresponding to each model identifier as an offline translation model.
[0096] In the disclosed embodiment, after the translation model corresponding to each model identifier is successfully installed, the computer device may determine the translation model corresponding to each model identifier as an offline translation model. At this time, the offline translation model can translate document data without an Internet connection.
[0097] Step 340: In response to the user's model selection instruction, obtain the target model identifier selected by the user from the model selection instruction.
[0098] In the disclosed embodiment, when a user needs to translate document data of a target document, a model selection instruction may be sent to a computer device, and the computer device may respond to the user's model selection instruction and obtain a target model identifier selected by the user from the model selection instruction.
[0099] Step 350: Select an offline translation model corresponding to the target model identifier from a plurality of pre-installed offline translation models as a target offline translation model.
[0100] In the embodiment of the present disclosure, the computer device may select an offline translation model corresponding to the target model identifier from a plurality of pre-installed offline translation models as the target offline translation model.
[0101] Therefore, the offline translation model can be deployed in the computer device according to the user's needs, and the target offline translation model can be selected according to the user's needs to perform document translation, which can improve the applicability and user experience of the document translation.
[0102] Figure 4 Schematic diagram of the structure of a document offline translation device provided by an embodiment of the present disclosure, which can be understood as the above-mentioned computer device or some functional modules in the above-mentioned computer device. Figure 4 As shown, the document offline translation device 400 includes:
[0103] A first acquisition module 410 is used to acquire document data of a target document and a target language for translating the target document;
[0104] A filling module 420 is used to fill the document data and the target language into the preset chat template to obtain a target chat template;
[0105] The translation module 430 is used to input the target chat template into a pre-installed target offline translation model, and translate the document data into the target language based on the target offline translation model to obtain translation data of the document data.
[0106] Optionally, the first acquisition module includes:
[0107] Get the submodule to get the file name of the target document;
[0108] An extraction submodule, used for extracting the target document type to which the target document belongs from the file name;
[0109] A determination submodule, used to determine a target document loader corresponding to a target document type based on a mapping relationship between a document type and a document loader;
[0110] The parsing submodule is used to parse the target document based on the target document loader to obtain the document data corresponding to the target document.
[0111] Optionally, the filling module includes:
[0112] The segmentation submodule is used to segment the document data in sequence according to a preset segmentation method starting from the first character of the document data to obtain multiple text blocks corresponding to the document data;
[0113] A sorting submodule is used to sort multiple text blocks in sequence according to the segmentation order to construct a text block sequence corresponding to the document data;
[0114] A filling submodule is used to fill the text block and the target language into the preset chat template for each text block in the text block sequence corresponding to the document data, so as to obtain a target chat template corresponding to the text block;
[0115] Optionally, the above translation module includes:
[0116] The translation submodule is used to input the target chat templates corresponding to each text block into a preset target offline translation model in sequence, and translate each text block in the text block sequence into the target language in sequence based on the target offline translation model to obtain translation data of the document data.
[0117] Optionally, the preset segmentation method includes at least one of segmentation by character, segmentation by sentence, segmentation by paragraph and segmentation by page.
[0118] Optionally, any two adjacent text blocks in the above text block sequence have a preset number of overlapping characters.
[0119] Optionally, the document offline translation device includes:
[0120] A second acquisition module is used to respond to the user's model selection instruction and acquire the target model identifier selected by the user from the model selection instruction;
[0121] The selection module is used to select an offline translation model corresponding to the target model identifier from a plurality of pre-installed offline translation models as a target offline translation model.
[0122] Optionally, the document offline translation device includes:
[0123] A third acquisition module, configured to respond to a model download instruction from a user and acquire at least one model identifier requested to be downloaded and a download address corresponding to each model identifier from the model download instruction;
[0124] A download module, for downloading the translation model corresponding to each model identifier from the download address corresponding to the model identifier and installing it into the local storage space;
[0125] The determination module is used to determine the translation model corresponding to each model identifier as the offline translation model.
[0126] The document offline translation device provided in the embodiments of the present disclosure can implement the method of any of the above embodiments, and its execution method and beneficial effects are similar, which will not be repeated here.
[0127] The embodiments of the present disclosure also provide a computer device, which includes a processor and a memory, wherein a computer program is stored in the memory, and when the computer program is executed by the processor, the method of any of the above embodiments can be implemented, and its execution method and beneficial effects are similar and will not be repeated here.
[0128] Figure 5 is a schematic diagram of the structure of a computer device provided by an embodiment of the present disclosure, such as Figure 5 As shown, the computer device 500 may include a processor 510 and a memory 520, wherein the memory 520 stores a computer program 521, and when the computer program 521 is executed by the processor 510, the method provided by any of the above embodiments can be implemented, and its execution method and beneficial effects are similar, which will not be repeated here.
[0129] Of course, to simplify, Figure 5 Only some of the components related to the present invention in the computer device 500 are shown, and components such as a bus, an input / output interface, an input device, and an output device are omitted. In addition, according to specific application conditions, the computer device 500 may also include any other appropriate components.
[0130] The embodiments of the present disclosure provide a computer-readable storage medium in which a computer program is stored. When the computer program is executed by a processor, the method of any of the above embodiments can be implemented. The execution method and beneficial effects are similar and will not be described in detail here.
[0131] The above-mentioned computer readable storage medium can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can include, for example, but is not limited to, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0132] The computer program may be written in any combination of one or more programming languages to write program codes for performing the operations of the disclosed embodiments, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer device, partially on the user's device, as a separate software package, partially on the user's computer device and partially on a remote computer device, or entirely on a remote computer device or server.
[0133] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present disclosure (but not limited to) by each other to form a technical solution.
[0134] In addition, although each operation is described in a specific order, this should not be understood as requiring these operations to be performed in the specific order shown or in a sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination mode.
[0135] The above description is only a specific embodiment of the present disclosure, so that those skilled in the art can understand or implement the present disclosure. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure will not be limited to the embodiments described herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A document offline translation method, characterized in that: include: Acquire document data of a target document and a target language for translation of the target document; Filling the document data and the target language into a preset chat template to obtain a target chat template; The target chat template is input into a pre-installed target offline translation model, and the document data is translated into a target language based on the target offline translation model to obtain translation data of the document data.
2. The method according to claim 1, characterized in that The step of obtaining the document data of the target document includes: Get the file name of the target document; Extracting the target document type to which the target document belongs from the file name; Determine a target document loader corresponding to the target document type based on a mapping relationship between the document type and the document loader; The target document is parsed based on the target document loader to obtain document data corresponding to the target document.
3. The method according to claim 1, characterized in that The step of filling the document data and the target language into a preset chat template to obtain a target chat template includes: Starting from the first character of the document data, segmenting the document data in sequence according to a preset segmentation method to obtain a plurality of text blocks corresponding to the document data; Sorting the multiple text blocks in sequence according to the segmentation order to construct a text block sequence corresponding to the document data; For each text block in the text block sequence corresponding to the document data, fill the text block and the target language into a preset chat template to obtain a target chat template corresponding to the text block; The step of inputting the target chat template into a preset target offline translation model, translating the document data into a target language based on the target offline translation model, and obtaining translation data of the document data includes: The target chat templates corresponding to the text blocks are sequentially input into a preset target offline translation model, and each text block in the text block sequence is sequentially translated into a target language based on the target offline translation model to obtain translation data of the document data.
4. The method according to claim 3, characterized in that The preset segmentation method includes at least one of segmentation by character, segmentation by sentence, segmentation by paragraph and segmentation by page.
5. The method according to claim 3, characterized in that: Any two adjacent text blocks in the text block sequence have a preset number of overlapping characters.
6. The method according to claim 1, characterized in that Before inputting the target chat template into a pre-installed target offline translation model, the method further includes: In response to a model selection instruction of a user, obtaining a target model identifier selected by the user from the model selection instruction; An offline translation model corresponding to the target model identifier is selected from a plurality of pre-installed offline translation models as a target offline translation model.
7. The method according to claim 6, characterized in that Before the step of obtaining the target model identifier selected by the user from the model selection instruction in response to the user's model selection instruction, the method further comprises: In response to a model download instruction from a user, obtaining at least one model identifier requested to be downloaded and a download address corresponding to each model identifier from the model download instruction; For each download address corresponding to the model identifier, download the translation model corresponding to the model identifier from the download address and install it into the local storage space; The translation model corresponding to each of the model identifiers is determined as an offline translation model.
8. A document offline translation device, characterized in that: include: A first acquisition module, used to acquire document data of a target document and a target language for translation of the target document; A filling module, used to fill the document data and the target language into a preset chat template to obtain a target chat template; The translation module is used to input the target chat template into a pre-installed target offline translation model, and translate the document data into a target language based on the target offline translation model to obtain translation data of the document data.
9. A computer device, characterized in that: include: A memory and a processor, wherein a computer program is stored in the memory, and when the computer program is executed by the processor, the document offline translation method according to any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by the processor, the document offline translation method according to any one of claims 1 to 7 is implemented.
