Word vector training method and device for large language model and medium
By using Huffman trees and negative sampling technology for word vector training in large language models, the problem of slow convergence speed of existing methods is solved, more efficient word vector training is achieved, and the application needs of large language models are met.
Patent Information
- Application Number
- CN202410666725.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-27
- Publication Date
- 2024-08-23
AI Technical Summary
Existing word vector training methods have the problem of slow convergence in large language model applications, making it difficult to meet demand.
Adopt a word vector training method based on Huffman trees and negative sampling. By constructing a Huffman tree for encoding and generating negative sampling data sets, the preset word vector training model is used for word vector training, which reduces the amount of model calculation and improves training efficiency. .
Significantly improves the efficiency of word vector training, meets the application needs of large language models, and improves model performance.
Smart Images

Figure CN118536504A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of natural language processing technology, and in particular to a word vector training method, device and medium for a large language model. Background Art
[0002] Natural language processing (NLP) is a branch of artificial intelligence and linguistics. This field explores how to process and use natural language, make computers "understand" human language, convert computer data into natural language, and convert natural language into a form that is easier for computer programs to process. In natural language processing, the first problem people have to solve is how to make the model understand human text information. As the basic unit in natural language processing, words are also important units for expressing the main idea of a sentence. Word vectors, also known as word embeddings (distributed representation of words), are a general term for a group of language modeling and feature learning techniques in natural language processing, that is, words from the vocabulary are mapped to vectors expressed in real numbers. The training of word vectors maps words into vectors, which is an indispensable bridge for models such as artificial neural networks to understand human natural language.
[0003] With the advent of the era of large language models, the privatization and service-oriented deployment of large language models are becoming more and more common, and various large models are emerging one after another. Regardless of the model, the first data input into the model is the word vector, and the word vector even has a greater impact on the model than the quality of the original data. Common word vector training methods such as CBOW and Skip-Gram have the problem that the convergence speed becomes slow as the vocabulary becomes larger. Therefore, the existing word vector training methods are difficult to meet the application requirements of large language models. Summary of the invention
[0004] The present invention aims to solve the above technical problems. In view of the limitations of the existing word vector training methods, a word vector training method, device and medium based on Huffman tree and negative sampling are proposed, which can effectively improve the efficiency of word vector training to meet the application requirements of large language models.
[0005] In a first aspect, the present invention provides a word vector training method for a large language model, comprising:
[0006] Get training corpus;
[0007] Constructing a Huffman tree based on the training corpus and performing encoding to obtain a Huffman encoding result;
[0008] Constructing a negative sampling data set based on the training corpus;
[0009] Based on the Huffman coding result and the negative sampling data set, word vector training is performed using a preset word vector training model.
[0010] In some implementation schemes, after obtaining the training corpus, the step further includes performing data preprocessing on the training corpus;
[0011] The data preprocessing includes: performing word segmentation on the training corpus to obtain a word segmentation result, performing data encoding based on the word segmentation result to obtain a dictionary encoding result, and counting the word frequency of each word based on the dictionary encoding result.
[0012] In some implementation schemes, the word frequency of each word based on the dictionary encoding result is specifically:
[0013] The number of times each word appears in the training corpus is counted based on the dictionary encoding result, the word probability of each word is calculated based on the number, and the word frequency peak clipping transformation is performed according to the word probability to determine the word frequency of each word.
[0014] In some implementation schemes, the Huffman tree is constructed based on the training corpus and the Huffman encoding result is obtained by encoding:
[0015] Take each word as a leaf node and the frequency of each word as the weight of the node;
[0016] Arrange the leaf nodes in ascending order of weight to form a node queue, select two nodes with the smallest weight from the node queue each time to construct a binary tree, set the weight of the root node of the binary tree to the sum of the weights of its left and right subtrees, and insert the root node into the queue until only one newly inserted root node remains in the queue to obtain a Huffman tree;
[0017] For the Huffman tree, the code of the left subtree is specified to be 0, and the code of the right subtree is specified to be 1, and the Huffman coding result corresponding to the path of each word is obtained.
[0018] In some implementation schemes, constructing a negative sampling data set based on the training corpus specifically includes: setting the size of the sliding window to n, where n is a positive integer; using the sliding window to select negative example words from the training corpus; and forming a negative sampling data set based on all the selected negative example words.
[0019] In some implementation schemes, the preset word vector training model is specifically a CBOW model or a Skip-Gram model.
[0020] In some embodiments, the word vector training using a preset word vector training model based on the Huffman coding result and the negative sampling data set specifically includes:
[0021] Initialize the parameters of the preset word vector training model according to the Huffman encoding result;
[0022] Based on the negative sampling data set, the parameters of the preset word vector training model and the output word vector are iteratively updated by the gradient ascent method until the gradient converges.
[0023] In a second aspect, the present invention provides a word vector training device for a large language model, the device comprising:
[0024] Acquisition module, used to obtain training corpus;
[0025] A Huffman coding module, used for constructing a Huffman tree based on the training corpus and performing coding to obtain a Huffman coding result;
[0026] A negative sampling module, used to construct a negative sampling data set based on the training corpus;
[0027] A training module is used to perform word vector training based on the Huffman coding result and the negative sampling data set using a preset word vector training model.
[0028] In a third aspect, the present invention provides a computer device comprising a processor and a storage device, wherein the storage device is suitable for storing multiple program codes, and the program codes are suitable for being loaded and run by the processor to execute the word vector training method for a large language model described in any one of the technical solutions of the above method.
[0029] In a fourth aspect, a computer-readable storage medium is provided, which stores a plurality of program codes, wherein the program codes are suitable for being loaded and run by a processor to execute the word vector training method for a large language model described in any one of the above technical solutions.
[0030] The above one or more technical solutions of the present invention have at least one or more of the following beneficial effects: in implementing the technical solution of the present invention, first obtain training corpus; construct a Huffman tree based on the training corpus and encode it to obtain a Huffman encoding result; construct a negative sampling data set based on the training corpus; and perform word vector training using a preset word vector training model based on the Huffman encoding result and the negative sampling data set. The present application proposes an improved word vector training method, which reduces the amount of model calculation and improves model performance by adopting Huffman trees and negative sampling, thereby achieving a significant improvement in the efficiency of word vector training, thereby better meeting the application requirements of large language models. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] The preferred embodiments of the present invention are described below in conjunction with the accompanying drawings, in which:
[0032] Figure 1 This is a flowchart of the main steps of a word vector training method for a large language model in an embodiment of the present application;
[0033] Figure 2 yes Figure 1 A schematic diagram of a specific implementation step of step S102;
[0034] Figure 3 This is an exemplary schematic diagram of the implementation process of constructing a Huffman tree and performing encoding;
[0035] Figure 4 yes Figure 1 A schematic diagram of a specific implementation step of step S103;
[0036] Figure 5 It is a schematic block diagram of a word vector training device for a large language model according to an embodiment of the present application. DETAILED DESCRIPTION
[0037] Some embodiments of the present invention are described below with reference to the accompanying drawings. It should be understood by those skilled in the art that these embodiments are only used to explain the technical principles of the present invention and are not intended to limit the protection scope of the present invention.
[0038] In the description of the present invention, "module" and "processor" may include hardware, software or a combination of the two. A module may include hardware circuits, various suitable sensors, communication ports, and memories, and may also include software parts, such as program codes, or a combination of software and hardware. The processor may be a central processing unit, a microprocessor, an image processor, a digital signal processor, or any other suitable processor. The processor has data and / or signal processing functions. The processor may be implemented in software, hardware, or a combination of the two. Non-temporary computer-readable storage media include any suitable medium that can store program codes, such as a magnetic disk, a hard disk, an optical disk, a flash memory, a read-only memory, a random access memory, and the like. The term "A and / or B" means all possible combinations of A and B, such as only A, only B, or A and B. The term "at least one A or B" or "at least one of A and B" has a similar meaning to "A and / or B", and may include only A, only B, or A and B. The singular terms "one" and "the" may also include plural forms.
[0039] Here we first explain some terms involved in the present invention.
[0040] Large Language Model (LLM): Also known as a large language model, it is an artificial intelligence model designed to understand and generate human language. Generally, LLM refers to a language model containing tens of billions or more parameters, such as GPT-3, GPT-4 and ChatGLM in China. There are many characters or words in natural language, which need to be converted into word vectors before they can be processed by the neural network of the large language model.
[0041] Word2vec: It is a tool for generating word vectors launched by Google in 2013. The word2vec tool mainly includes two models: Skip-Gram and Continuous Bag of Words (CBOW). The training process of Word2Vec is to use words as input to predict other words in the context, or use other words in the context as input to predict the current word. By learning the association between word contexts, word vectors that can represent the relationship between words can be trained.
[0042] Word vector: also known as word embedding, is a general term for a set of language modeling and feature learning techniques in natural language processing (NLP), in which words or phrases from a vocabulary are mapped to vectors of real numbers. Conceptually, it involves mathematical embedding from a one-dimensional space for each word to a continuous vector space with lower dimensions.
[0043] CBOW: CBOW is the abbreviation of continuous bag of words, which is translated into Chinese as "continuous bag of words model". It is a neural network model for generating word vectors, proposed by Tomas Mikolov et al. in 2013. Word vector is a method of representing words as real number vectors of fixed length, which can capture the semantic and grammatical relationships between words. The basic idea of CBOW is to predict the word itself given the context of a word (that is, other words in the window). For example, for the sentence "The cat cl imbed up the tree", if the window size is 5, then when the central word is "cl imbed", the context words are "The", "cat", "up" and "the". The CBOW model requires that the probability distribution of "cl imbed" be calculated based on these four context words.
[0044] Skip-Gram: Translated into Chinese as "skip word model", contrary to the CBOW model, the basic idea of the Skip-Gram model is to predict context words based on the central word.
[0045] Huffman coding: also known as Huffman Coding, is a coding method proposed by Huffman in 1952. This method constructs codewords with the shortest average length of different prefixes based entirely on the probability of character occurrence. It is sometimes called the optimal coding and is generally called Huffman coding.
[0046] Huffman Tree: Given N weighted words as N leaf nodes, a binary tree is constructed. If the weighted path length of the tree is minimized, such a binary tree is called the optimal binary tree, also known as the Huffman Tree. The Huffman tree is the tree with the shortest weighted path length. The weight refers to the weight on the node. The node with a larger weight is closer to the root.
[0047] Negative sampling: refers to sampling a part of negative samples from a bunch of negative samples for model training. The reason why not all negative samples are used is mainly to reduce the training complexity of the model. In Word2Vec, there is also a negative sampling operation. When predicting a word, in theory, it is necessary to predict all words and then take the word with the largest prediction value. However, the number of all words is too large and the computational complexity is too high. Therefore, in order to reduce the complexity, sampling is performed from all words (this process is called negative sampling), sampling some words and target words, and letting the model take out the word with the largest prediction value.
[0048] The specific implementation methods of the present application are further described in detail below in conjunction with the drawings and examples.
[0049] The embodiment of the present application provides a word vector training method for a large language model, which performs word vector training based on a Huffman tree and negative sampling. Figure 1 As shown, it is a flow chart of the main steps of a word vector training method for a large language model provided according to an embodiment of the present application. As shown in the figure, it mainly includes the following steps S101 to S105.
[0050] Step S101: Obtain training corpus;
[0051] Specifically in this embodiment, a plurality of different application scenarios may be set according to the actual application requirements of the large language model, and for each application scenario, a training corpus corresponding to the application scenario may be obtained, wherein the training corpus corresponding to each application scenario may include a plurality of words of different word types.
[0052] Furthermore, after obtaining the training corpus, a process of data preprocessing the training corpus is also included, and the data preprocessing specifically includes:
[0053] (1) Tokenize the training corpus to obtain the tokenization result;
[0054] Specifically in this embodiment, an existing tokenization tool in the prior art can be used to tokenize and obtain the tokenization result. For example, for Chinese tokenization, Jieba or HanLP toolkit can be used for tokenization, or for the training corpus related to a professional field, tokenization can be performed according to the word list maintained by itself. It can be understood that when using a tokenization tool to tokenize the training corpus, punctuation marks can also be removed, as well as stop words such as "de" and "di". In addition, according to the types of words in the training corpus, a Chinese tokenization tool and an English tokenization tool can be used for tokenization processing simultaneously.
[0055] (2) Perform data encoding based on the tokenization result to obtain the dictionary encoding result;
[0056] Specifically in this embodiment, the process of data encoding can be understood as the process of compiling the tokenization result into a dictionary. The dictionary is composed of many related elements, and each pair of elements contains a key and a value. Such an element is called a key-value pair, generally denoted as (key: value). In this embodiment, the key of the dictionary is the word itself, and the value is an incrementing number.
[0057] (3) Statistically calculate the word frequency of each word based on the dictionary encoding result.
[0058] Among them, the word frequency (Term Frequency, TF) refers to the number of times a given word appears in the training corpus (such as an article).
[0059] In a specific embodiment, the step of statistically calculating the word frequency of each word based on the dictionary encoding result is specifically: statistically calculate the number of times each word appears in the training corpus based on the dictionary encoding result, and determine the word frequency of each word based on the number of times.
[0060] In a specific embodiment, the step of statistically calculating the word frequency of each word based on the dictionary encoding result is specifically: statistically calculate the number of times each word appears in the training corpus based on the dictionary encoding result, calculate the word probability of each word based on the number of times, and perform a word frequency peak clipping transformation according to the word probability to determine the word frequency of each word.
[0061] For example, the word frequency peak clipping transformation can specifically be to perform a three-quarter power calculation on the word probability.
[0062] Step S102: Construct a Huffman tree based on the training corpus and perform encoding to obtain the Huffman encoding result;
[0063] Specifically in this embodiment, based on the training corpus, the words contained in the training corpus and the frequency of each word can be obtained.
[0064] In a specific implementation manner, the specific implementation steps of constructing a Huffman tree based on the training corpus and encoding to obtain a Huffman encoding result are as follows: Figure 2 As shown, the following steps S1021 to S1023 are included:
[0065] Step S1021: taking each word as a leaf node and the frequency of each word as the weight of the node;
[0066] Step S1022: Arrange the leaf nodes in ascending order of weight to form a node queue, select two nodes with the smallest weights from the node queue each time to construct a binary tree, set the weight of the root node of the binary tree to the sum of the weights of its left and right subtrees, and insert the root node into the queue, until only one newly inserted root node remains in the queue to obtain a Huffman tree;
[0067] Step S1023: For the Huffman tree, the code of the left subtree is set to 0, and the code of the right subtree is set to 1, and the Huffman coding result corresponding to the path of each word is obtained.
[0068] For example, assuming that the weights corresponding to 5 consecutive words are (1, 3, 4, 2, 5) in order, the process of constructing the Huffman tree is as follows: 1. Arrange the weights from small to large (1, 2, 3, 4, 5); 2. Select the two trees with the smallest weights from the arrangement and merge them. The weight of the merged root node is the sum of the weights of the two leaf nodes, and the root node is added to the arrangement and re-arranged from small to large; 3. Repeat step 2 until there is only one root node left in the sequence, and then for the Huffman tree, stipulate that the left subtree is encoded as 0 and the right subtree is encoded as 1, and the Huffman coding results corresponding to the paths of each word can be obtained. For example, the node corresponding to weight 1 is encoded as 000, the node corresponding to weight 2 is encoded as 001, the node corresponding to weight 3 is encoded as 01, the node corresponding to weight 4 is encoded as 10, and the node corresponding to weight 5 is encoded as 11. Figure 3 , which is a schematic diagram of the above exemplary process of constructing a Huffman tree and the final Huffman tree and its encoding.
[0069] Step S103: constructing a negative sampling data set based on the training corpus;
[0070] In this embodiment, the specific implementation method of constructing the negative sampling data set based on the training corpus is as follows: Figure 4 As shown, the steps S1031 to S1033 are included:
[0071] Step S1031: setting the size of the sliding window to n, where n is a positive integer;
[0072] Specifically, the size of the sliding window is n, which means that the number of words in the sliding window is n, and the words in the sliding window can be understood to include central words and context words.
[0073] Step S1032: using the sliding window to select negative example words from the training corpus;
[0074] Specifically, taking the value of n equal to 7 as an example, the words contained in the training corpus and the word frequency of each word can be obtained based on the training corpus. The selection of negative example words from the training corpus is specifically: the word in the middle of the 7 consecutive words in the sliding window is defined as x, that is, the central word, and the 3 words before and after x are defined as y, that is, context words; based on the sliding window, other words that are not y and conform to the word frequency distribution are selected from the training corpus as negative example words. In the embodiment of the present application, when the value of n is 7, the quantity and quality of the sampled negative example words can reach a good level, which is conducive to improving the model performance of subsequent word vector training.
[0075] It can be understood that sampling based on word frequency distribution selects negative samples according to the frequency of occurrence of words in the corpus, that is, words with lower word frequencies have a higher probability of being selected as negative example words, while words with higher word frequencies have a lower probability of being selected.
[0076] Step S1033: forming a negative sampling data set based on all selected negative example words.
[0077] Specifically, in an actual application scenario, the size of the sliding window, that is, the number n of words in each sliding window, can be set as needed.
[0078] Step S104: Based on the Huffman coding result and the negative sampling data set, word vector training is performed using a preset word vector training model.
[0079] Specifically in this embodiment, the preset word vector training model can be a CBOW model or a Skip-Gram model.
[0080] In a specific implementation, the word vector training using a preset word vector training model based on the Huffman coding result and the negative sampling data set specifically includes:
[0081] Initialize the parameters of the preset word vector training model according to the Huffman encoding result;
[0082] Based on the negative sampling data set, the parameters of the preset word vector training model and the output word vector are iteratively updated by the gradient ascent method until the gradient converges.
[0083] It is understandable that the output layer (normalization function softmax) of the common word vector training model is a log linear classifier for sampling, and the distribution probability of each word needs to be calculated. When the vocabulary is large, the calculation cost will be very high. Based on the word vector training method of this application, the Huffman number (Huffman Tree) is used to replace the output layer. Huffman Tree is a hierarchical softmax. Because it is a binary tree, the calculation complexity of each sotfmax is reduced from the original V to log2V; negative sampling (Negat i ve sampling) is another method to solve the problem of softmax calculation amount. Only a small amount of negative samples are sampled each time, and the entire vocabulary does not need to be calculated. Therefore, this application is an improved word vector training method, which can effectively improve the efficiency of word vector training compared to the existing word vector training method.
[0084] The improved word vector training method provided in the embodiments of the present application can train word vectors based on various neural network models for generating word vectors, such as the typical Skip-Gram model and the CBOW model. In practical applications, compared with the Skip-Gram model, the CBOW model is more in line with the requirements of interchange between natural language and machine language in daily communication. Therefore, the application scenarios of word vector training based on the CBOW model and the method of the present application and applying them to large language models are more extensive.
[0085] Furthermore, the present application also provides a word vector training device for a large language model.
[0086] See attached Figure 5 , Figure 5 This is a main structural block diagram of a word vector training device for a large language model according to an embodiment of the present application. As shown in the figure, the device mainly includes the following modules:
[0087] An acquisition module 201 is used to acquire training corpus;
[0088] A Huffman coding module 202 is used to construct a Huffman tree based on the training corpus and perform coding to obtain a Huffman coding result;
[0089] A negative sampling module 203, configured to construct a negative sampling data set based on the training corpus;
[0090] The training module 204 is used to perform word vector training based on the Huffman coding result and the negative sampling data set using a preset word vector training model.
[0091] For the sake of ease of explanation, the above introduction to the word vector training device for a large language model only shows the part related to the embodiment of the present application. For specific technical details not disclosed, please refer to the method part of the embodiment of the present application.
[0092] It should be understood that since the setting of each module is only for illustrating the functional units of the present application, the physical devices corresponding to these modules may be the processor itself, or a part of the software in the processor, a part of the hardware, or a part of the combination of software and hardware. Therefore, the number of each module in the figure is only schematic.
[0093] It is understood by those skilled in the art that each module in the device can be adaptively split or merged. Such splitting or merging of specific modules will not cause the technical solution to deviate from the principle of the present application, and therefore, the technical solutions after splitting or merging will fall within the protection scope of the present application.
[0094] It is understood by those skilled in the art that all or part of the processes in the method for implementing the above-mentioned embodiment of the present application can also be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable storage medium may include: any entity or device, medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory, random access memory, electrical carrier signal, telecommunication signal and software distribution medium, etc. that can carry the computer program code.
[0095] Furthermore, the present application also provides a computer device.
[0096] In an embodiment of a computer device according to the present application, the computer device mainly includes a processor and a storage device, the storage device can be configured to store a program for executing the word vector training method for a large language model of the above method embodiment, and the processor can be configured to execute the program in the storage device, which includes but is not limited to executing the program for the word vector training method for a large language model of the above method embodiment. For ease of explanation, only the parts related to the embodiments of the present application are shown. For specific technical details not disclosed, please refer to the method part of the embodiments of the present application.
[0097] In the embodiment of the present application, the computer device may be a control device device formed by various electronic devices. In some possible implementations, the computer device may include multiple storage devices and multiple processors. The program for executing the word vector training method for a large language model of the above method embodiment can be divided into multiple subprograms, each of which can be loaded and run by a processor to execute different steps of the word vector training method of the above method embodiment. Specifically, each subprogram can be stored in different storage devices, and each processor can be configured to execute programs in one or more storage devices to jointly implement the word vector training method for a large language model of the above method embodiment, that is, each processor executes different steps of the above method embodiment to jointly implement the word vector training method of the above method embodiment.
[0098] The above-mentioned multiple processors may be processors deployed on the same device. For example, the above-mentioned computer device may be a high-performance device composed of multiple processors, and the above-mentioned multiple processors may be processors configured on the high-performance device. In addition, the above-mentioned multiple processors may also be processors deployed on different devices. For example, the above-mentioned computer device may be a server cluster, and the above-mentioned multiple processors may be processors on different servers in the server cluster.
[0099] Furthermore, the present application also provides a computer-readable storage medium.
[0100] In a computer-readable storage medium embodiment according to the present application, the computer-readable storage medium can be configured to store a program for executing the above-mentioned method embodiment for a word vector training method for a large language model, and the program can be loaded and run by a processor to implement the above-mentioned word vector training method for a large language model. For ease of explanation, only the parts related to the embodiment of the present application are shown. For specific technical details not disclosed, please refer to the method part of the embodiment of the present application. The computer-readable storage medium can be a storage device formed by various electronic devices. Optionally, the computer-readable storage medium in the embodiment of the present application is a non-temporary computer-readable storage medium.
[0101] So far, the technical solutions of the present invention have been described in conjunction with the preferred embodiments shown in the accompanying drawings. However, it is easy for those skilled in the art to understand that the protection scope of the present invention is obviously not limited to these specific embodiments. Without departing from the principle of the present invention, those skilled in the art can make equivalent changes or substitutions to the relevant technical features, and the technical solutions after these changes or substitutions will fall within the protection scope of the present invention.
Claims
1. A word vector training method for a large language model, characterized in that: The method comprises: Get training corpus; Constructing a Huffman tree based on the training corpus and performing encoding to obtain a Huffman encoding result; Constructing a negative sampling data set based on the training corpus; Based on the Huffman coding result and the negative sampling data set, word vector training is performed using a preset word vector training model.
2. A word vector training method for a large language model according to claim 1, characterized in that: After obtaining the training corpus, the step further includes performing data preprocessing on the training corpus; The data preprocessing includes: performing word segmentation on the training corpus to obtain a word segmentation result, performing data encoding based on the word segmentation result to obtain a dictionary encoding result, and counting the word frequency of each word based on the dictionary encoding result.
3. A word vector training method for a large language model according to claim 2, characterized in that: The word frequency of each word based on the dictionary encoding result is specifically: The number of times each word appears in the training corpus is counted based on the dictionary encoding result, the word probability of each word is calculated based on the number, and the word frequency peak clipping transformation is performed according to the word probability to determine the word frequency of each word.
4. A word vector training method for a large language model according to claim 2, characterized in that: The Huffman encoding result obtained by constructing a Huffman tree based on the training corpus and encoding is specifically: Take each word as a leaf node and the frequency of each word as the weight of the node; Arrange the leaf nodes in ascending order of weight to form a node queue, select two nodes with the smallest weight from the node queue each time to construct a binary tree, set the weight of the root node of the binary tree to the sum of the weights of its left and right subtrees, and insert the root node into the queue until only one newly inserted root node remains in the queue to obtain a Huffman tree; For the Huffman tree, the code of the left subtree is specified to be 0, and the code of the right subtree is specified to be 1, and the Huffman coding result corresponding to the path of each word is obtained.
5. The word vector training method for a large language model according to claim 1, characterized in that: The constructing of a negative sampling data set based on the training corpus specifically includes: setting the size of a sliding window to n, where n is a positive integer; using the sliding window to select negative example words from the training corpus; and forming a negative sampling data set based on all the selected negative example words.
6. A word vector training method for a large language model according to claim 1, characterized in that: The preset word vector training model is specifically a CBOW model or a Skip-Gram model.
7. The word vector training method for a large language model according to claim 1, characterized in that: The performing word vector training using a preset word vector training model based on the Huffman coding result and the negative sampling data set specifically includes: Initialize the parameters of the preset word vector training model according to the Huffman encoding result; Based on the negative sampling data set, the parameters of the preset word vector training model and the output word vector are iteratively updated by the gradient ascent method until the gradient converges.
8. A word vector training device for a large language model, characterized in that: The device comprises: Acquisition module, used to obtain training corpus; A Huffman coding module, used for constructing a Huffman tree based on the training corpus and performing coding to obtain a Huffman coding result; A negative sampling module, used to construct a negative sampling data set based on the training corpus; A training module is used to perform word vector training based on the Huffman coding result and the negative sampling data set using a preset word vector training model.
9. A computer device comprising a processor and a storage device, wherein the storage device is suitable for storing a plurality of program codes, characterized in that: The program code is suitable for being loaded and run by the processor to execute a word vector training method for a large language model according to any one of claims 1 to 7.
10. A computer-readable storage medium storing a plurality of program codes, characterized in that: The program code is suitable for being loaded and run by a processor to execute a word vector training method for a large language model according to any one of claims 1 to 7.
Citation Information
Cited By
Man-machine interaction method and system for legal consultation
CN119938873A
