Language detection method, device, electronic device and storage medium
Through the language detection method of the two-level classification model, the first classification model is used for preliminary detection and when the conditions are met, the second classification model with higher accuracy is used, which solves the problem of low accuracy of language identification in the existing technology and improves the accuracy of language identification. Accuracy and speed.
Patent Information
- Application Number
- CN202011540408.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-23
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2040-12-23
AI Technical Summary
Existing language detection technology is difficult to accurately identify languages when processing large-scale real-world texts. In particular, the recognition accuracy is low when distinguishing between similar languages, which affects the effectiveness of applications such as machine translation.
Using a two-level classification model, the first classification model is used for language detection. If the result meets the preset conditions, the second classification model with higher recognition accuracy is called for secondary detection to improve the accuracy of language identification.
The accuracy and speed of language recognition are significantly improved, especially the ability to distinguish between similar languages, and the logic and efficiency of language detection are optimized.
Smart Images

Figure CN112528682B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, specifically to the field of artificial intelligence technology such as natural language processing and deep learning, and in particular to a language detection method, device, electronic device and storage medium. Background Art
[0002] In natural language processing, language detection is a technique for identifying the language of a given text. Language detection is a key step in natural language processing, especially when processing large-scale text in the real world, we usually need to perform corresponding processing based on the language information of the text.
[0003] For example, in machine translation, users may input text in any language as the source language. In this case, the system needs to determine the language of the user input in order to translate it correctly. Language detection is essentially a text classification task, and the language corresponds to the category of the text. Summary of the invention
[0004] The present application provides a language detection method, device, electronic device and storage medium.
[0005] According to one aspect of the present application, a language detection method is provided, comprising:
[0006] Get input text;
[0007] Calling a first classification model to perform language detection on the input text to generate a first language recognition result; and
[0008] If the first language recognition result meets a preset condition, a second classification model is called to perform language detection on the input text to generate a second language recognition result, wherein the recognition accuracy of the second classification model is higher than that of the first classification model.
[0009] According to another aspect of the present application, a language detection device is provided, comprising:
[0010] The acquisition module is used to obtain the input text;
[0011] A first detection module, configured to call a first classification model to perform language detection on the input text to generate a first language recognition result; and
[0012] The second detection module is used to call a second classification model to perform language detection on the input text to generate a second language recognition result if the first language recognition result meets a preset condition, wherein the recognition accuracy of the second classification model is higher than that of the first classification model.
[0013] According to another aspect of the present application, there is provided an electronic device, including:
[0014] at least one processor; and
[0015] a memory communicatively connected to the at least one processor; wherein,
[0016] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the language detection method described in the above-mentioned embodiment.
[0017] According to another aspect of the present application, a non-transitory computer-readable storage medium storing computer instructions is provided, on which a computer program is stored, and the computer instructions are used to enable the computer to execute the language detection method described in the above-mentioned embodiment.
[0018] According to another aspect of the present application, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the language detection method described in the embodiment of the first aspect is implemented.
[0019] Other effects of the above optional manner will be described below in conjunction with specific embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present application.
[0021] Figure 1 A flow chart of a language detection method provided in an embodiment of the present application;
[0022] Figure 2 A flowchart of another language detection method provided in an embodiment of the present application;
[0023] Figure 3 A schematic diagram of the network structure of the first classification model provided in an embodiment of the present application;
[0024] Figure 4 A flowchart of another language detection method provided in an embodiment of the present application;
[0025] Figure 5 A schematic diagram of the network structure of the second classification model provided in an embodiment of the present application;
[0026] Figure 6 A schematic diagram of the structure of a language detection device provided in an embodiment of the present application; and
[0027] Figure 7 4 is a block diagram of an electronic device of a language detection device according to an embodiment of the present application. DETAILED DESCRIPTION
[0028] The following is a description of exemplary embodiments of the present application in conjunction with the accompanying drawings, including various details of the embodiments of the present application to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present application. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0029] The following describes the language detection method, device, electronic device and storage medium of the embodiments of the present application with reference to the accompanying drawings.
[0030] Artificial intelligence is a discipline that studies the use of computers to simulate certain human thought processes and intelligent behaviors (such as learning, reasoning, thinking, planning, etc.). It includes both hardware-level technical fields and software-level technologies. Artificial intelligence hardware technologies generally include technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, and big data processing; artificial intelligence software technologies include computer vision technology, speech recognition technology, natural language processing technology, as well as deep learning, big data processing technology, knowledge graph technology, and other major directions.
[0031] Natural language processing is an important direction in the fields of computer science and artificial intelligence. It studies various theories and methods that can achieve effective communication between humans and computers using natural language. Natural language processing is a science that integrates linguistics, computer science, and mathematics.
[0032] Deep learning is a new research direction in the field of machine learning. Deep learning is the study of the inherent laws and representation levels of sample data. The information obtained in the learning process is of great help in the interpretation of data such as text, images and sounds. Its ultimate goal is to enable machines to have analytical learning capabilities like humans and to be able to recognize data such as text, images and sounds. Deep learning is a complex machine learning algorithm that has achieved results in speech and image recognition that far exceed previous related technologies.
[0033] The language detection method provided in the embodiment of the present application can be executed by an electronic device, and the electronic device can be a PC (Personal Computer), a tablet computer or a handheld computer, etc., without any limitation here.
[0034] In the embodiment of the present application, the electronic device may be provided with a processing component, a storage component and a drive component. Optionally, the drive component and the processing component may be integrated, the storage component may store an operating system, an application program or other program modules, and the processing component implements the language detection method provided in the embodiment of the present application by executing the application program stored in the storage component.
[0035] Figure 1 A flow chart of a language detection method provided in an embodiment of the present application.
[0036] The language detection method of the embodiment of the present application can also be implemented by the language detection device provided in the embodiment of the present application. The device can be configured in an electronic device to call the first classification model to perform language detection on the acquired input text to generate a first language recognition result, and when the first language recognition result meets the preset conditions, call the second classification model to perform language detection on the acquired input text to generate a second language recognition result.
[0037] As a possible situation, the language detection method of the embodiment of the present application can also be executed on the server side. The server can be a cloud server, and the language detection method can be executed on the cloud.
[0038] like Figure 1 As shown, the language detection method may include:
[0039] Step 101, obtaining input text. It should be noted that the input text described in this embodiment can be text expressed in various written languages, for example, Chinese text, English text, Russian text, Malay text, Chinese and English mixed text, etc. The input text can include a sentence, a paragraph or a chapter, such as a news article, etc.
[0040] In an embodiment of the present application, the input text may include text information input by the user through voice recognition and input content input by the user into the input method system through the input method. The input method system can convert the input content into word candidates for the input text according to the user's current input method, and provide them to the user for selection. The user can input text information through a variety of input methods, such as keyboard, touchpad, mouse, etc. At the same time, the user can also choose any input method to input text information, such as pinyin, Wubi, strokes, handwriting, English, small language keyboard, etc., without any limitation here.
[0041] As a possible situation, the above-mentioned input text may also include text information obtained by the user through copying and pasting.
[0042] Specifically, the electronic device can obtain input information (input text) input by the user into the input method system through the input method. For example, the user inputs a text description in Chinese through the input method.
[0043] Step 102: Call a first classification model to perform language detection on the input text to generate a first language recognition result.
[0044] As a possible situation, the first classification model mentioned above can be improved on the basis of the open source FastText model.
[0045] It should be noted that the first classification model described in this embodiment can be trained in advance and pre-stored in the storage space of the electronic device to facilitate retrieval and application. The storage space is not limited to entity-based storage space, such as a hard disk. The above storage space can also be the storage space of a network hard disk connected to the electronic device (cloud storage space).
[0046] In an embodiment of the present application, after obtaining the input text, the electronic device may first pre-process the input text to remove punctuation, consecutive blank characters, Arabic numerals, emoticons, emoticon images, etc. in the input text, and convert the text into lowercase, thereby eliminating interference items for subsequent language detection, thereby improving the accuracy of subsequent language detection.
[0047] Specifically, after obtaining the preprocessed input text, the electronic device can first call out the first classification model from its own storage space, and then input the input text into the first classification model, thereby performing language detection on the preprocessed input text through the first classification model to obtain the first language recognition result output by the first classification model.
[0048] Step 103: If the first language recognition result meets the preset conditions, the second classification model is called to perform language detection on the input text to generate a second language recognition result, wherein the recognition accuracy of the second classification model is higher than the recognition accuracy of the first classification model. The preset conditions can be calibrated according to actual conditions.
[0049] It should be noted that the first classification model described in this embodiment may be trained in advance and pre-stored in the storage space of the electronic device to facilitate retrieval and application.
[0050] Specifically, after obtaining the first language recognition result, the electronic device can first determine whether the first language recognition result meets the preset conditions. If the first language recognition result meets the preset conditions, the second classification model can be called out from its own storage space, and the preprocessed input text can be input into the second classification model again, thereby performing language detection on the preprocessed input text through the second classification model to obtain the second language recognition result output by the second classification model, and use the second language recognition result as the final recognition result.
[0051] In the embodiment of the present application, the training and generation of the first classification model and the second classification model can be performed by a related server, which can be a cloud server or a computer host. A communication connection is established between the server and the electronic device that can execute the language detection method provided in the embodiment of the application, and the communication connection can be at least one of a wireless network connection and a wired network connection. The server can send the trained first classification model and the second classification model to the electronic device so that the electronic device can call it when needed, thereby greatly reducing the computing pressure of the electronic device.
[0052] In an embodiment of the present application, an input text is first obtained, and then a first classification model is called to perform language detection on the input text to generate a first language recognition result. If the first language recognition result meets a preset condition, a second classification model is called to perform language detection on the input text to generate a second language recognition result. Finally, the second language recognition result can be used as the final recognition result, so that the language of the input text can be effectively detected, thereby improving the accuracy of the language recognition result.
[0053] Furthermore, in one embodiment of the present application, the above-mentioned language detection method may also include that if the first language recognition result does not meet a preset condition, the first language recognition result may be used as the final recognition result.
[0054] Specifically, after obtaining the preprocessed input text, the electronic device can first call out the first classification model from its own storage space, and then input the preprocessed input text into the first classification model, so as to perform language detection on the preprocessed input text through the first classification model to obtain the first language recognition result output by the first classification model. After obtaining the first language recognition result, the electronic device determines whether the first language recognition result meets the preset conditions. If the first language recognition result does not meet the preset conditions, it means that there is no need to call the second classification model to perform language detection on the preprocessed input text. At this time, the electronic device can directly provide the first language recognition result to the user as the final recognition result, thereby improving the speed of language detection.
[0055] Furthermore, in one embodiment of the present application, the following steps can be used to determine whether the first language recognition result meets the preset conditions: query a similar language group based on the first language recognition result to determine whether a similar language exists; if so, determine that the first language recognition result meets the preset conditions; if not, determine that the first language recognition result does not meet the preset conditions.
[0056] Specifically, after obtaining the first language recognition result, the electronic device can parse the first language recognition result to determine whether the language given by the first language recognition result is in the similar language group. If so, it means that there is a similar language in the above-mentioned input text. At this time, it can be determined that the first language recognition result meets the preset conditions, and the second classification model can be called to perform language detection on the input text to generate the second language recognition result; if not, it means that there is no similar language in the above-mentioned input text. At this time, it can be determined that the first language recognition result does not meet the preset conditions, and the first language recognition result can be directly provided to the user as the final recognition result. Since the first language recognition result does not meet the preset conditions, it means that the input text detected this time does not need to call the second classification model to continue language detection, thereby optimizing the logic of the language detection method and improving the speed of language detection.
[0057] In order to clearly explain the above embodiment, in one embodiment of the present application, Figure 2 As shown, the first classification model can perform language detection on the input text through the following steps to generate a first language recognition result:
[0058] Step 201: Generate a plurality of first characters according to an input text.
[0059] In an embodiment of the present application, a plurality of first characters may be generated according to an input text and a preset character generation algorithm, wherein the preset character generation algorithm may be calibrated according to actual conditions.
[0060] Step 202: Generate a corresponding first character category feature vector according to a plurality of first characters, and generate a first character feature vector according to a plurality of first characters.
[0061] Specifically, after acquiring the input text, the electronic device may first preprocess the input text to obtain the preprocessed input text, and input the preprocessed input text into the first classification model. The first classification model may generate a plurality of first characters according to the preprocessed input text and a preset character generation algorithm, and then classify the plurality of first characters according to the encoding, and count the distribution of the plurality of first characters in different character categories to obtain the first character category feature, and may encode the first character category feature (i.e., obtain a vector) by word embedding to obtain the first character category feature vector.
[0062] At the same time, the first classification model can also count the character-level n-gram features of the first characters and perform hash value calculation to obtain the first character feature. Then the first classification model can encode the first character feature in a word embedding manner (i.e., obtain a vector) to obtain a first character feature vector.
[0063] In an embodiment of the present application, the first classification model may obtain multiple first character category feature vectors and first character feature vectors. In this case, the first classification model may respectively average the multiple first character category feature vectors and the first character feature vectors, and use the corresponding average values as the final first character category feature vector and the first character feature vector.
[0064] Step 203: extract a plurality of first words from the input text, and generate a first word feature vector according to the plurality of first words.
[0065] In an embodiment of the present application, the input text may be extracted according to a preset word extraction algorithm to obtain a plurality of first words, wherein the preset word extraction algorithm may be calibrated according to actual conditions.
[0066] Specifically, the first classification model can extract multiple first words from the preprocessed input text according to a preset word extraction algorithm, for example, extracting words from the preprocessed input text using spaces as separators. Then the first classification model extracts first word features from the multiple first words, and can encode the first word features (i.e., obtain a vector) in a word embedding manner to obtain a first word feature vector.
[0067] In an embodiment of the present application, there may be multiple first word feature vectors obtained by the first classification model. In this case, the electronic device may average the multiple first word feature vectors and use the corresponding average value as the final first word feature vector.
[0068] Step 204: Generate a first language recognition result according to the first character category feature vector, the first character feature vector and the first word feature vector.
[0069] Specifically, see Figure 3 , the first classification model may include a hidden layer and a classifier. After obtaining the first character category feature vector, the first character feature vector and the first word feature vector, the first classification model may first connect the three feature vectors in series and send them to the hidden layer, and then send the data output after the hidden layer processing to the classifier to classify the data through the classifier, thereby obtaining the first language recognition result. Therefore, the language of the input text can be effectively detected through the first classification model.
[0070] In order to clearly explain the above embodiment, in one embodiment of the present application, Figure 4 As shown, the second classification model can detect the language of the input text through the following steps to generate a second language recognition result:
[0071] Step 401: Generate a plurality of second characters according to input text.
[0072] In the embodiment of the present application, multiple second characters may also be generated according to the input text and a preset character generation algorithm.
[0073] Step 402: Generate a corresponding second character category feature vector according to the plurality of second characters, and generate a second character feature vector according to the plurality of second characters.
[0074] Specifically, after determining that the first language recognition result meets the preset conditions, the electronic device may input the preprocessed input text into the second classification model. The second classification model may generate a plurality of second characters according to the preprocessed input text and a preset character generation algorithm, and then classify the plurality of second characters according to the encoding, and count the distribution of the plurality of second characters in different character categories to obtain a second character category feature, and may encode the second character category feature (i.e., obtain a vector) in a word embedding manner to obtain a second character category feature vector.
[0075] At the same time, the second classification model can also count the character-level n-gram features of multiple second characters and perform hash value calculation to obtain the second character feature. Then the second classification model can encode the second character feature in a word embedding manner (i.e., obtain a vector) to obtain a second character feature vector.
[0076] In an embodiment of the present application, the second character category feature vector and the second character feature vector obtained by the second classification model may be multiple. In this case, the second classification model may respectively average the multiple second character category feature vectors and the second character feature vectors, and use the corresponding average values as the final second character category feature vector and the second character feature vector.
[0077] Step 403: extract a plurality of second words from the input text, and generate a second word feature vector and a word feature vector according to the plurality of second words.
[0078] In the embodiment of the present application, the input text may also be extracted according to a preset word extraction algorithm to obtain a plurality of second words.
[0079] Specifically, the second classification model can extract multiple second words from the preprocessed input text according to a preset word extraction algorithm, for example, extracting words from the preprocessed input text using spaces as separators. Then the second classification model extracts second word features from the multiple second words, and can encode the second word features (i.e., obtain a vector) in a word embedding manner to obtain a second word feature vector.
[0080] At the same time, the second classification model can also count the word-level n-gram features in multiple second words and perform hash value calculation to obtain word features. Then the second classification model can encode the word features in a word embedding manner (i.e., find a vector) to obtain a word feature vector.
[0081] In an embodiment of the present application, the second classification model may obtain multiple second word feature vectors and multiple word feature vectors. In this case, the second classification model may average the multiple second word feature vectors and multiple word feature vectors respectively, and use the corresponding average values as the final second word feature vector and word feature vector.
[0082] Step 404, generating a second language recognition result according to the second character category feature vector, the second character feature vector, the second word feature vector and the word feature vector.
[0083] Specifically, see Figure 5 , the second classification model may also include a hidden layer and a classifier. After obtaining the second character category feature vector, the second character feature vector, the second word feature vector and the word feature vector, the second classification model may first connect the above four feature vectors in series and send them to the hidden layer, and then send the data output after the hidden layer processing to the classifier to classify the data through the classifier, thereby obtaining the second language recognition result. Therefore, for input texts containing similar languages, secondary detection through the second classification model with higher recognition accuracy can improve the ability to distinguish similar languages and significantly improve the detection effect of similar languages.
[0084] In order to improve the language detection effect of short texts, in one embodiment of the present application, before calling the first classification model to perform language detection on the input text to generate a first language recognition result, it may also include: matching the input text with a preset vocabulary, and if a corresponding vocabulary is matched, using the language corresponding to the vocabulary as the recognition result.
[0085] It should be noted that the preset vocabulary described in this embodiment may be generated in advance and pre-stored in the storage space of the electronic device for easy retrieval and use.
[0086] Specifically, after obtaining the preprocessed input text, the electronic device can first call out the preset word list from its own storage space, and match the preprocessed input text with the preset word list. If the corresponding word list is matched, the language corresponding to the word list is used as the recognition result, and the recognition result can be directly provided to the user. Therefore, before calling the first classification model, the language of the input text is first detected by adding the preset word list, which makes up for the disadvantage of the classification model in short text recognition, thereby significantly improving the language detection effect of short text.
[0087] Figure 6 A schematic diagram of the structure of a language detection device provided in an embodiment of the present application.
[0088] The language detection device of the embodiment of the present application can also be configured in an electronic device to call the first classification model to perform language detection on the acquired input text to generate a first language recognition result, and when the first language recognition result meets the preset conditions, call the second classification model to perform language detection on the acquired input text to generate a second language recognition result.
[0089] like Figure 1 As shown, the language detection device 600 may include: an acquisition module 610 , a first detection module 620 and a second detection module 630 .
[0090] The acquisition module 610 is used to acquire input text. It should be noted that the input text described in this embodiment can be a text expressed in various written languages, such as Chinese text, English text, Russian text, Malay text, Chinese and English mixed text, etc. The input text can include a sentence, a paragraph or a chapter, such as a news article, etc.
[0091] In an embodiment of the present application, the input text may include text information input by the user through voice recognition and input content input by the user into the input method system through the input method. The input method system can convert the input content into word candidates for the input text according to the user's current input method, and provide them to the user for selection. The user can input text information through a variety of input methods, such as keyboard, touchpad, mouse, etc. At the same time, the user can also choose any input method to input text information, such as pinyin, Wubi, strokes, handwriting, English, small language keyboard, etc., without any limitation here.
[0092] As a possible situation, the above-mentioned input text may also include text information obtained by the user through copying and pasting.
[0093] Specifically, the acquisition module 610 can acquire input information (input text) inputted by the user into the input method system through the input method, for example, the user inputs a text description in Chinese through the input method.
[0094] The first detection module 620 is used to call the first classification model to perform language detection on the input text to generate a first language recognition result.
[0095] As a possible situation, the first classification model mentioned above can be improved on the basis of the open source FastText model.
[0096] It should be noted that the first classification model described in this embodiment can be trained in advance and pre-stored in the storage space of the electronic device to facilitate retrieval and application. The storage space is not limited to entity-based storage space, such as a hard disk. The above storage space can also be the storage space of a network hard disk connected to the electronic device (cloud storage space).
[0097] In an embodiment of the present application, after the acquisition module 610 acquires the input text, the first detection module 620 may first pre-process the input text to remove punctuation, consecutive blank characters, Arabic numerals, emoticons, emoticon images, etc. in the input text, and convert the text into lowercase, thereby eliminating interference items for subsequent language detection, thereby improving the accuracy of subsequent language detection.
[0098] Specifically, after the first detection module 620 obtains the preprocessed input text, it can first call out the first classification model from the storage space of the electronic device, and then input the input text into the first classification model, so as to perform language detection on the preprocessed input text through the first classification model to obtain the first language recognition result output by the first classification model.
[0099] The second detection module 630 is used to call the second classification model to perform language detection on the input text to generate a second language recognition result if the first language recognition result meets the preset condition, wherein the recognition accuracy of the second classification model is higher than the recognition accuracy of the first classification model. The preset condition can be calibrated according to actual conditions.
[0100] It should be noted that the first classification model described in this embodiment may be trained in advance and pre-stored in the storage space of the electronic device to facilitate retrieval and application.
[0101] Specifically, after the first detection module 620 obtains the first language recognition result, the second detection module 630 may first determine whether the first language recognition result meets the preset conditions. If the first language recognition result meets the preset conditions, the second classification model may be called out from its own storage space, and the preprocessed input text may be input into the second classification model again, thereby performing language detection on the preprocessed input text through the second classification model to obtain the second language recognition result output by the second classification model, and use the second language recognition result as the final recognition result.
[0102] In the embodiment of the present application, the input text is obtained by the acquisition module, and the first detection module calls the first classification model to perform language detection on the input text to generate a first language recognition result. If the first language recognition result meets the preset condition, the second detection module calls the second classification model to perform language detection on the input text to generate a second language recognition result. In this way, the language of the input text can be effectively detected, thereby improving the accuracy of the language recognition result.
[0103] In one embodiment of the present application, the first detection module 620 is specifically used to: generate multiple first characters based on the input text; generate corresponding first character category feature vectors based on the multiple first characters, and generate a first character feature vector based on the multiple first characters; extract multiple first words from the input text, and generate a first word feature vector based on the multiple first words; and generate a first language recognition result based on the first character category feature vector, the first character feature vector and the first word feature vector.
[0104] In one embodiment of the present application, the second detection module 630 is specifically used to: generate multiple second characters based on the input text; generate corresponding second character category feature vectors based on the multiple second characters, and generate a second character feature vector based on the multiple second characters; extract multiple second words from the input text, and generate second word feature vectors and word feature vectors based on the multiple second words; and generate a second language recognition result based on the second character category feature vector, the second character feature vector, the second word feature vector and the word feature vector.
[0105] In one embodiment of the present application, Figure 6 As shown, the language detection device 600 may also include a recognition module 640, wherein the recognition module 640 is used to match the input text with a preset vocabulary before the first detection module calls the first classification model to perform language detection on the input text to generate a first language recognition result; if a corresponding vocabulary is matched, the language corresponding to the vocabulary is used as the recognition result.
[0106] In one embodiment of the present application, the second detection module 630 determines whether the first language recognition result meets the preset condition in the following manner: querying a similar language group based on the first language recognition result to determine whether a similar language exists; if so, determining that the first language recognition result meets the preset condition; and if not, determining that the first language recognition result does not meet the preset condition.
[0107] In one embodiment of the present application, the second detection module 630 is further configured to: if the first language recognition result does not meet a preset condition, use the first language recognition result as the final recognition result.
[0108] It should be noted that the above explanation of the embodiment of the language detection method is also applicable to the language detection device of this embodiment, and will not be repeated here.
[0109] The language detection device of the embodiment of the present application obtains the input text through the acquisition module, and performs language detection on the input text through the first detection module calling the first classification model to generate a first language recognition result. If the first language recognition result meets the preset condition, the second detection module calls the second classification model to perform language detection on the input text to generate a second language recognition result. In this way, the language of the input text can be effectively detected, thereby improving the accuracy of the language recognition result.
[0110] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.
[0111] Figure 7 A schematic block diagram of an example electronic device 700 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.
[0112] like Figure 7 As shown, the device 700 includes a computing unit 701, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 702 or a computer program loaded from a storage unit 708 into a random access memory (RAM) 703. In the RAM 703, various programs and data required for the operation of the device 700 can also be stored. The computing unit 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.
[0113] A number of components in the device 700 are connected to the I / O interface 705, including: an input unit 706, such as a keyboard, a mouse, etc.; an output unit 707, such as various types of displays, speakers, etc.; a storage unit 708, such as a disk, an optical disk, etc.; and a communication unit 709, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 709 allows the device 700 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0114] The computing unit 701 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 701 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 701 performs the various methods and processes described above, such as the language detection method. For example, in some embodiments, the language detection method may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 708. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 700 via the ROM 702 and / or the communication unit 709. When the computer program is loaded into the RAM 703 and executed by the computing unit 701, one or more steps of the language detection method described above may be performed. Alternatively, in other embodiments, the computing unit 701 may be configured to perform the language detection method in any other appropriate manner (e.g., by means of firmware).
[0115] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0116] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0117] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer 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 foregoing.
[0118] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0119] The systems and techniques described herein can be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), the Internet, and a blockchain network.
[0120] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship between the client and the server is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services ("Virtual Private Server", or "VPS" for short). The server may also be a server of a distributed system, or a server combined with a blockchain.
[0121] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0122] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A language detection method, comprising: Get input text; Calling a first classification model to perform language detection on the input text to generate a first language recognition result; as well as If the first language recognition result meets a preset condition, calling a second classification model to perform language detection on the input text to generate a second language recognition result, wherein the recognition accuracy of the second classification model is higher than the recognition accuracy of the first classification model; The second classification model performs language detection on the input text to generate a second language recognition result through the following steps, including: generating a plurality of second characters according to the input text; generating a corresponding second character category feature vector according to the plurality of second characters, and generating a second character feature vector according to the plurality of second characters; Extracting a plurality of second words from the input text, and generating a second word feature vector and a word feature vector according to the plurality of second words; and Concatenate the second character category feature vector, the second character feature vector, the second word feature vector, and the word feature vector, and generate the second language recognition result according to the concatenated feature vectors; The step of extracting a plurality of second words from the input text and generating a second word feature vector and a word feature vector according to the plurality of second words comprises: Extracting a plurality of second words from the preprocessed input text according to a preset word extraction algorithm; Extracting a second word feature from the plurality of second words, and encoding the second word feature in a word embedding manner to obtain a second word feature vector; Counting word-level n-gram features of a plurality of the second words, and performing hash value calculation to obtain word features; Encoding the word features by word embedding to obtain the word feature vector; The step of generating a corresponding second character category feature vector according to the plurality of second characters comprises: generating a plurality of second characters according to the preprocessed input text and a preset character generation algorithm; The multiple second characters are classified according to the codes, and the distribution of the multiple second characters in different character categories is counted to obtain second character category features, and the second character category features are encoded by word embedding to obtain the second character category feature vector.
2. The language detection method according to claim 1, wherein: The first classification model performs language detection on the input text to generate a first language recognition result by the following steps: generating a plurality of first characters according to the input text; Generating corresponding first character category feature vectors according to the plurality of first characters, and generating first character feature vectors according to the plurality of first characters; Extracting a plurality of first words from the input text, and generating a first word feature vector according to the plurality of first words; as well as The first language recognition result is generated according to the first character category feature vector, the first character feature vector and the first word feature vector.
3. The language detection method according to claim 1, wherein: Before calling the first classification model to perform language detection on the input text to generate a first language recognition result, the method further includes: Matching the input text with a preset vocabulary; and If a corresponding vocabulary is matched, the language corresponding to the vocabulary is used as the recognition result.
4. The language detection method according to claim 1, wherein: The following steps are performed to determine whether the first language recognition result meets the preset conditions: querying a similar language group according to the first language recognition result to determine whether there is a similar language; If so, determining that the first language recognition result meets the preset condition; as well as If not, it is determined that the first language recognition result does not meet the preset condition.
5. The language detection method according to claim 1 or 4, wherein: Also includes: If the first language recognition result does not meet the preset condition, the first language recognition result is used as the final recognition result.
6. A language detection device, comprising: The acquisition module is used to obtain the input text; A first detection module, configured to call a first classification model to perform language detection on the input text to generate a first language recognition result; as well as a second detection module, configured to, if the first language recognition result satisfies a preset condition, call a second classification model to perform language detection on the input text to generate a second language recognition result, wherein the recognition accuracy of the second classification model is higher than that of the first classification model; The second detection module is specifically used for: generating a plurality of second characters according to the input text; generating a corresponding second character category feature vector according to the plurality of second characters, and generating a second character feature vector according to the plurality of second characters; Extracting a plurality of second words from the input text, and generating a second word feature vector and a word feature vector according to the plurality of second words; and Concatenate the second character category feature vector, the second character feature vector, the second word feature vector, and the word feature vector, and generate the second language recognition result according to the concatenated feature vectors; The step of extracting a plurality of second words from the input text and generating a second word feature vector and a word feature vector according to the plurality of second words comprises: Extracting a plurality of second words from the preprocessed input text according to a preset word extraction algorithm; Extracting a second word feature from the plurality of second words, and encoding the second word feature in a word embedding manner to obtain a second word feature vector; Counting word-level n-gram features of a plurality of the second words, and performing hash value calculation to obtain word features; Encoding the word features by word embedding to obtain the word feature vector; The step of generating a corresponding second character category feature vector according to the plurality of second characters comprises: generating a plurality of second characters according to the preprocessed input text and a preset character generation algorithm; The multiple second characters are classified according to the codes, and the distribution of the multiple second characters in different character categories is counted to obtain second character category features, and the second character category features are encoded by word embedding to obtain the second character category feature vector.
7. The language detection device according to claim 6, wherein: The first detection module is specifically used to: generating a plurality of first characters according to the input text; Generating corresponding first character category feature vectors according to the plurality of first characters, and generating first character feature vectors according to the plurality of first characters; Extracting a plurality of first words from the input text, and generating a first word feature vector according to the plurality of first words; as well as The first language recognition result is generated according to the first character category feature vector, the first character feature vector and the first word feature vector.
8. The language detection device according to claim 6, further comprising: The recognition module is used to match the input text with a preset vocabulary before the first detection module calls the first classification model to perform language detection on the input text to generate a first language recognition result; if a corresponding vocabulary is matched, the language corresponding to the vocabulary is used as the recognition result.
9. The language detection device according to claim 6, wherein: The second detection module determines that the first language recognition result meets a preset condition in the following manner: querying a similar language group according to the first language recognition result to determine whether there is a similar language; If so, determining that the first language recognition result meets the preset condition; as well as If not, it is determined that the first language recognition result does not meet the preset condition.
10. The language detection device according to claim 6 or 9, wherein the second detection module is further configured to: If the first language recognition result does not meet the preset condition, the first language recognition result is used as the final recognition result.
11. An electronic device, characterized in that: include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the language detection method according to any one of claims 1 to 5.
12. A non-transitory computer-readable storage medium storing computer instructions, characterized in that: The computer instructions are used to enable the computer to execute the language detection method according to any one of claims 1 to 5.
13. A computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the language detection method according to any one of claims 1 to 5 is implemented.
