Model training method and device, content generation method and device, and electronic device

By introducing rotational position encoding and a list of identifier symbols into the LLaMA model, the problems of slow model training speed and difficulty in information discrimination are solved, achieving faster training speed and higher information quality.

CN117435814BActive Publication Date: 2026-11-06MICRO DREAM TECHTRONIC NETWORK TECH CHINACO
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311560900.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-11-21
Publication Date
2026-11-06
Estimated Expiration
2043-11-21

AI Technical Summary

Technical Problem

Existing LLaMA models exhibit periodic oscillations during training, resulting in slow training speeds and difficulty in effectively distinguishing between content and auxiliary information, thus affecting the quality and acceptance rate of pushed information.

Method used

By introducing encoding units into the LLaMA model to encode rotational positions, the difference in rotation angle between two data units and the distance satisfy a monotonically increasing relationship. Furthermore, a list of identifier symbols is added during model training to distinguish between content and auxiliary information.

Benefits of technology

It eliminates periodic oscillations during training, improves model training speed, and better distinguishes between content and auxiliary information, thereby enhancing the quality and acceptance rate of pushed information.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117435814B_ABST
    Figure CN117435814B_ABST
Patent Text Reader

Abstract

This application provides a model training method, a content generation method and apparatus, an electronic device, and a storage medium. The method includes: acquiring first sample data, wherein the first sample data includes multiple data units; inputting the first sample data into an improved LLaMA model to obtain feature quantities, wherein the improved LLaMA model includes an encoding unit for rotating and positioning the feature vectors of the multiple data units, the distance between two data units is a first distance, the angle difference between the rotation angles of the feature vectors of two data units after rotation and positioning encoding is a first angle difference, and the first distance and the first angle difference satisfy a monotonically increasing relationship; training the improved LLaMA model based on the feature quantities until the improved LLaMA model converges, obtaining a trained content generation model. This application accelerates the training speed of the improved LLaMA model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of recommender systems, and more particularly to a model training method, a content generation method and apparatus, and an electronic device. Background Technology

[0002] Currently, people's daily lives are increasingly reliant on the internet. In particular, people are becoming more and more accustomed to obtaining content through applications. This content can be news, blog posts, or other forms of information. However, even when the application is not running, it's worth considering pushing information to users. If a user is interested in the pushed information, they may open the corresponding application to view it. The generation of push notifications can be implemented using large language models such as the LLaMA model.

[0003] Therefore, how to train an LLaMA model is an urgent problem to be solved. Summary of the Invention

[0004] This application provides a model training method, a content generation method and apparatus, and an electronic device, thereby accelerating the training speed of the model.

[0005] The technical solution of this application is implemented as follows:

[0006] In a first aspect, this application provides a model training method. The method includes: acquiring first sample data, wherein the first sample data includes multiple data units; inputting the first sample data into an improved LLaMA model to obtain feature quantities, wherein the improved LLaMA model includes an encoding unit, the encoding unit being used to perform rotational position encoding on the feature vectors of the multiple data units, the distance between two data units is a first distance, the angle difference between the rotation angles of the feature vectors of the two data units after rotational position encoding is a first angle difference, and the first distance and the first angle difference satisfy a monotonically increasing relationship; training the improved LLaMA model based on the feature quantities until the improved LLaMA model converges, obtaining a trained content generation model.

[0007] In some possible implementations, the encoding unit may include a rotation matrix. The rotation matrix is ​​used for encoding the rotational positions of the feature vectors of multiple data units. The rotation matrix can be:

[0008]

[0009] Among them, A i Let N be the rotation matrix, N1 be the size of the rotation matrix, N1 be an even number and greater than 1, i be a positive integer not greater than N, and N be the number of data units in the first sample data.

[0010] The angle parameter of the rotation matrix can be:

[0011]

[0012] in, Let N be the angle parameter, N2 be the maximum number of data units in the first sample data, and t be an even number with a value ranging from 0 to N1-2.

[0013] In some possible implementations, the relative rotation matrix, which is composed of the rotation matrices corresponding to the eigenvectors of the two data units, can be:

[0014]

[0015] Among them, A i,j Let N represent the relative rotation matrix, where i and j are the positions of two data units in multiple data units, and i and j are both positive integers not greater than N.

[0016] In some possible implementations, the feature vector corresponding to one of the two data units may be a Q vector, and the feature vector corresponding to the other data unit may be a K vector.

[0017] In a second aspect, this application provides a content generation method. The method includes: acquiring first data of a blog post to be recommended, wherein the first data includes multiple data units; inputting the multiple data units into a content generation model to obtain feature quantities, wherein the content generation model is obtained according to the model training method described in any one of the first aspects and its possible embodiments; and determining recommended content corresponding to the blog post to be recommended based on the feature quantities.

[0018] In some possible implementations, the first data may further include identifiers and auxiliary information. The auxiliary information is used to characterize the blog post to be recommended. The identifier is used to identify the auxiliary information. The method may further include: determining the identifier based on the first data; determining the auxiliary information in the first data based on the identifier; and adding the auxiliary information to the recommended content.

[0019] In some possible implementations, multiple data units may include the blog post content of the post to be recommended. Auxiliary information may include at least one of the following: the identifier of the post to be recommended, the identifier of the blogger of the post to be recommended, the number of followers of the blogger, whitelist type, authentication type, authentication reason, tags of the post to be recommended, and tags of the blogger.

[0020] In a third aspect, this application provides a model training apparatus. The apparatus includes an acquisition module, a generation module, and a training module. The acquisition module is configured to acquire first sample data. The first sample data includes multiple data units. The generation module is configured to input the first sample data into an improved LLaMA model to obtain feature quantities. The improved LLaMA model includes an encoding unit. The encoding unit is used to perform rotational position encoding on the feature vectors of the multiple data units. The distance between two data units is a first distance. The angle difference between the rotation angles of the feature vectors of two data units after rotational position encoding is a first angle difference. The first distance and the first angle difference satisfy a monotonically increasing relationship. The training module is configured to train the improved LLaMA model based on the feature quantities until the improved LLaMA model converges, obtaining a trained content generation model.

[0021] In some possible implementations, the encoding unit may include a rotation matrix. The rotation matrix is ​​used for encoding the rotational positions of the feature vectors of multiple data units. The rotation matrix can be:

[0022]

[0023] Among them, A i Let N be the rotation matrix, N1 be the size of the rotation matrix, N1 be an even number and greater than 1, i be a positive integer not greater than N, and N be the number of data units in the first sample data.

[0024] The angle parameter of the rotation matrix can be:

[0025]

[0026] in, Let N be the angle parameter, N2 be the maximum number of data units in the first sample data, and t be an even number with a value ranging from 0 to N1-2.

[0027] In some possible implementations, the relative rotation matrix, which is composed of the rotation matrices corresponding to the eigenvectors of the two data units, can be:

[0028]

[0029] Among them, A i,j Let N represent the relative rotation matrix, where i and j are the positions of two data units in multiple data units, and i and j are both positive integers not greater than N.

[0030] In some possible implementations, the feature vector corresponding to one of the two data units may be a Q vector, and the feature vector corresponding to the other data unit may be a K vector.

[0031] In a fourth aspect, this application provides a content generation apparatus. The apparatus includes an acquisition module, a generation module, and a determination module. The acquisition module is configured to acquire first data of a blog post to be recommended. The first data includes multiple data units. The generation module is configured to input the multiple data units into a content generation model to obtain feature values. The content generation model is obtained according to the model training method described in any one of the first aspects and its possible embodiments. The determination module is configured to determine recommended content corresponding to the blog post to be recommended based on the feature values.

[0032] In some possible implementations, the first data may further include an identifier and auxiliary information. The auxiliary information is used to characterize the blog post to be recommended. The identifier is used to identify the auxiliary information. The method described above may also include an auxiliary information module. The auxiliary information module is configured to: determine an identifier based on the first data; determine the auxiliary information in the first data based on the identifier; and add the auxiliary information to the recommended content.

[0033] In some possible implementations, multiple data units may include the blog post content of the post to be recommended. Auxiliary information may include at least one of the following: the identifier of the post to be recommended, the identifier of the blogger of the post to be recommended, the number of followers of the blogger, whitelist type, authentication type, authentication reason, tags of the post to be recommended, and tags of the blogger.

[0034] In a fifth aspect, this application provides an electronic device. The electronic device includes a memory and a processor. The memory is used to store executable instructions. When the processor executes the executable instructions stored in the memory, it implements the method as described in any one of the first aspect, the second aspect, and their possible embodiments.

[0035] In a sixth aspect, this application provides a storage medium. Executable instructions are stored on the storage medium. When executed by a processor, the executable instructions implement the method as described in any one of the first aspect, the second aspect, and their possible embodiments.

[0036] In a seventh aspect, this application provides a computer program. The computer program includes code. When a computer executes the code, it implements the method as described in any one of the first aspect, the second aspect, and their possible embodiments.

[0037] This application has the following beneficial effects:

[0038] In this application, the encoding unit in the improved LLaMA model encodes the rotational position of the data units, and the angular difference between the rotation angles of two data units is monotonically increasing with the distance between the two data units. This method eliminates the periodic oscillation phenomenon during the training process of the LLaMA model, thereby accelerating the training speed of the improved LLaMA model. Attached Figure Description

[0039] Figure 1 This is a diagram illustrating push notifications from an application.

[0040] Figure 2 This is a flowchart illustrating the first embodiment of the model training method in this application.

[0041] Figure 3A This is a schematic diagram of the angle difference between the feature vectors of two data units in a related technology.

[0042] Figure 3B This is a schematic diagram of the angle difference between the feature vectors of two data units in an embodiment of this application.

[0043] Figure 4 This is a flowchart illustrating the second embodiment of the model training method in this application.

[0044] Figure 5 This is a flowchart illustrating the content generation method in the embodiments of this application.

[0045] Figure 6 This is a schematic diagram of the structure of the model training device in the embodiments of this application.

[0046] Figure 7 This is a schematic diagram of the structure of the content generation device in the embodiments of this application.

[0047] Figure 8 This is a schematic diagram of the structure of the electronic device in the embodiments of this application. Detailed Implementation

[0048] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the embodiments of this application will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be considered as limitations on this application. All other embodiments obtained by those skilled in the art without inventive effort are within the scope of protection of this application.

[0049] In the following description, references to "an embodiment," "some embodiments," etc., describe a subset of all possible embodiments. However, it is understood that "an embodiment" or "some embodiments" can be the same subset or different subsets of all possible embodiments, and can be combined with each other without conflict.

[0050] In the following description, the terms "first / second / third" are used merely to distinguish similar objects and do not represent a specific ordering of the objects. It is understood that "first / second / third" may be interchanged in a specific order or sequence where permitted, so that the embodiments of this application described herein can be implemented in an order other than that illustrated or described herein.

[0051] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.

[0052] Currently, people's daily lives are increasingly reliant on the internet. In particular, people are becoming more and more accustomed to obtaining content through applications. This content can be news, blog posts, or other forms of information. However, even when the application is not running, it's worth considering pushing information to users. If users are interested in the pushed information, they may open the corresponding application to view it.

[0053] Figure 1 This is a diagram illustrating application push notifications. For example... Figure 1 As shown, the interface displayed on screen 2 of electronic device 1 can display information 10 pushed by the application. The application can push information by calling the application interface of the operating system of electronic device 1 in the background. After reading the pushed information 10, the user can open the corresponding application by clicking on the window 11 where information 10 is located.

[0054] For example, a microblogging application (APP) can push microblogs to users. In this scenario, the text length of a microblog post is often very long, reaching hundreds or even thousands of words. However, the size of the window 11 on the electronic device 1 used to display the pushed information 10 is limited. To push microblogs, a summary needs to be generated based on the content of the microblog post, and a title needs to be generated if necessary. The generated summary (and title) are sometimes referred to as "copywriting".

[0055] Push notifications can be generated using large language models such as LLaMA. A key component of the LLaMA model is Rotary Position Embedding (RoPE). RoPE can achieve relative position encoding using absolute position encoding.

[0056] On the one hand, the data input into the LLaMA model can be a string. For example, a Weibo post is a string. The angle difference between the rotation angles of the feature vectors corresponding to two tokens (i.e., language fragments) in a Weibo post, after being encoded by rotation, is not monotonically increasing with the distance between these two tokens. This leads to oscillations during the training process of the LLaMA model, thus lengthening the training process and slowing down the model training speed.

[0057] On the other hand, a Weibo post may be accompanied by supplementary information. This supplementary information can be used to characterize the Weibo post or the blogger of the post. The LLaMA model has difficulty distinguishing this supplementary information from the content of the Weibo post. This leads to the generation of copy being influenced by the supplementary information, thus reducing the quality of the copy and lowering the likelihood of the pushed information being accepted.

[0058] In view of the above, this application provides a model training method, a content generation method and apparatus, and an electronic device.

[0059] Figure 2 This is a flowchart illustrating the first embodiment of the model training method in this application. Figure 2 As shown, the model training method of this application embodiment may include steps S210 to S230.

[0060] In step S210, the first sample data is obtained.

[0061] Here, the first sample data is the data used to train the LLaMA model. The first sample data may include multiple data units.

[0062] In different application scenarios, the first sample data can include different types of data. In one embodiment, the first sample data can include news. More specifically, the first sample data can include the text content of news articles. In one embodiment, the first sample data can include microblog posts (i.e., blog posts). More specifically, the first sample data can include the text content of microblog posts. In these application scenarios, the first sample data is composed of text, numbers, punctuation marks, etc. Each character, number, and punctuation mark in the first sample data can be considered a text unit. Therefore, each unit of text in the first sample data is a data unit.

[0063] In one example, the first sample data could be: "Second place: The six zodiac signs with the best tempers. Second place: Capricorn. Capricorns have a strong mindset, but even more so, they have a good temper that makes friends like them. They don't deliberately cause trouble for anyone, always fantasizing that they are full of a sense of justice, and they are very friendly to friends and even acquaintances. However, this doesn't mean they don't have a bad temper; it just means they know better how to control themselves. In addition, Capricorns are optimists, always with an excited expression, giving people a sense of closeness." Dividing this first sample data, we can obtain multiple data units as follows: "Second Place: The Six Zodiac Signs with the Best Temperament: Capricorn. Capricorns possess a strong mindset, but also have a good temper that makes friends like them. They won't intentionally cause trouble for anyone, always fantasizing about being full of a sense of justice, and are very friendly to friends and even acquaintances. However, this doesn't mean they don't have a bad temper; they just know how to control it better. Additionally, Capricorns are optimistic, always wearing an excited expression, giving people a sense of approachability." Here, multiple data units can be separated by slashes.

[0064] The first sample data may include data in different forms. In one embodiment, the first sample data may include raw data. In another embodiment, the first sample data may include feature vectors derived from the raw data, such as embeddings.

[0065] In one embodiment, the first sample data can be obtained from a blog post database. In another embodiment, the first sample data can be obtained from a blog post server. Of course, the first sample data can be obtained in other ways, and this application embodiment does not specifically limit this method.

[0066] In step S220, the first sample data is input into the LLaMA model to obtain the feature values.

[0067] Here, the LLaMA model includes an encoding unit. After the first sample data is input into the LLaMA model, the encoding unit performs rotational position encoding on multiple data units in the first sample data. More specifically, the encoding unit performs rotational position encoding on the feature vector of each data unit.

[0068] In one embodiment, after the encoding unit performs rotational position encoding on a data unit, the feature vector corresponding to that data unit is rotated by a certain angle. In other words, the feature vector corresponding to that data unit has a certain angle.

[0069] Since the first sample data includes multiple data units, there is a distance (or first distance) between any two data units. This distance is the number of data units that separate the two data units. For example, if one data unit is the i-th data unit and the other data unit is the j-th data unit, then the distance between these two data units can be equal to (ji).

[0070] For two data units, the angle difference (or first angle difference) between the angles after rotational position encoding and the distance between the two data units follows a monotonically increasing relationship. More specifically, when the distance between the two data units increases, the angle difference between them increases; when the distance between the two data units decreases, the angle difference between them decreases.

[0071] In one embodiment, the encoding unit may include a rotation matrix. The rotation operation performed by the encoding unit on the feature vector of the data unit is implemented using the rotation matrix. The rotation function implementing the rotation operation can be defined as:

[0072] rope(x,i)=xA i (1);

[0073] Where `rope()` is the rotation function, `x` is the eigenvector to be rotated, and `A` is the eigenvector to be rotated. i Let i be a rotation matrix, i be a positive integer not greater than N, and N be the number of data units in the first sample data.

[0074] The rotation matrix A i It can be represented as:

[0075]

[0076] Where N1 is the size of the rotation matrix, N1 is an even number and N1 is greater than 1.

[0077] The rotation matrix has a size of N1×N1. In one embodiment, the size of the rotation matrix can be 128×128. It is understood that N1 can also have other values, and this application does not specifically limit this.

[0078] It can be seen that in the above rotation matrix A i There are angle parameters in it. Let t be an even number, and its value range be from 0 to N(1-2). Then, in the rotation matrix A... i The angle parameters corresponding to the first and second columns (i.e., the first and second rows) can be The angle parameters corresponding to the third and fourth columns (i.e., the third and fourth rows) can be And so on.

[0079] In the rotation matrix, the angle parameter It can be represented as:

[0080]

[0081] Here, N2 represents the maximum number of data units in the first sample data set. It can be understood that N2 is a fixed value set for the LLaMA model. That is, the first sample data set can include a maximum of N2 data units.

[0082] The value of N2 can be set as needed. In one embodiment, N2 can be equal to 1024, 2048, 4096, or other values. It is understood that the larger the value of N2, the larger the length of the first sample data.

[0083] It should be noted that, in the embodiments of this application, the above-mentioned rotation matrix A is used. i and angle parameters The LLaMA model can also be called the improved LLaMA model.

[0084] In one embodiment, for any two data units among a plurality of data units, the inner product between their feature vectors can be expressed as:

[0085] x i A i (x j A j ) T = x i A i A j T x j T = x i A i,j x j T (4);

[0086] Where, x i x j For two data units, A i A j Let A be the rotation matrix corresponding to the eigenvectors of the two data units. i,j Let be the relative rotation matrix formed by the rotation matrices corresponding to the eigenvectors of the two data units. Let i and j be the positions of the two data units in the multiple data units, respectively.

[0087] Therefore, by combining formulas (2) and (4), we can obtain two data units x. i x j The relative rotation matrix between them:

[0088]

[0089] In one embodiment, the feature vectors of two data units obtained after relative position encoding can be calculated using a self-attention module (or self-attention mechanism). For example, the feature vector corresponding to one of the two data units can be a Q-vector (i.e., the query vector), and the feature vector corresponding to the other data unit can be a K-vector (i.e., the key vector). More specifically, the Q-vector can be the feature vector of the i-th row in the query matrix, and the K-vector can be the feature vector of the j-th row in the key matrix. Thus, the distance between the two data units is (ji). In this case, j is not equal to i.

[0090] In formula (5), It is the relative rotation matrix A i,j The angle difference. In other words, this angle difference is the first angle difference between the two data units.

[0091] Figure 3A This is a schematic diagram of the angle difference between the feature vectors of two data units in a related technology. Figure 3B This is a schematic diagram illustrating the angle difference between the feature vectors of two data units in an embodiment of this application. The horizontal axis represents the first distance between the two data units, and the vertical axis represents the first angle difference between the two data units.

[0092] It should be noted that, for the sake of simplicity, Figure 3A and Figure 3B Only the angle parameter is shown. The relevant angular difference. Angular parameters. This relates to the components of the first two dimensions of the eigenvector. Other angular parameters will not be discussed further here.

[0093] like Figure 3A As shown, with 2π for angle differences A modulo operation is performed to limit the angle difference to the range of 0 to 2π. It can be seen that when the distance between two data units is 6, the angle difference is 6; when the distance between two data units is 7, the angle difference is 0.7168. Clearly, the relationship between the distance between two data units and the angle difference is not monotonically increasing.

[0094] like Figure 3B As shown, the angle difference is also represented by 2π. A modulo operation is performed to limit the angle difference to the range of 0 to 2π. Figure 3B In this context, N² equals 2048. It can be seen that as the distance between two data units increases, the angle difference between them also increases. Clearly, the relationship between the distance and the angle difference between two data units is monotonically increasing.

[0095] Based on the rotational position encoding of multiple data units in the first sample data by the encoding module, the LLaMA model can further obtain the feature quantities of the first sample data. It is understood that the specific details of how the LLaMA model obtains the feature quantities of the first sample data are known and will not be elaborated upon here.

[0096] In one embodiment, the feature quantity can be used to indicate the probability that the corresponding prediction data unit is a word in the vocabulary. The prediction data unit can be a word or a symbol.

[0097] In step S230, the LLaMA model is trained based on the feature values ​​until the LLaMA model converges.

[0098] Based on the obtained features, the LLaMA model can be trained until one or more parameters in the LLaMA model converge. This yields a trained LLaMA model.

[0099] By following the steps S210 to S230 above, the trained content generation model can be obtained.

[0100] In this embodiment, the encoding unit in the LLaMA model encodes the rotational position of the data units, and the angular difference between the rotation angles of two data units is monotonically increasing with the distance between the two data units. This method eliminates the periodic oscillation phenomenon during the training process of the LLaMA model, thereby accelerating the training speed of the LLaMA model.

[0101] Figure 4 This is a flowchart illustrating the second embodiment of the model training method in this application. Figure 4 As shown, the model training method in this application embodiment may include steps S410 to S440.

[0102] It should be noted that the implementation method of this embodiment is different from... Figure 2 The implementation methods of the illustrated embodiments are partially the same. For ease of understanding, the differences between these embodiments will be mainly explained here.

[0103] In step S410, the first sample data is obtained.

[0104] Here, the first sample data includes multiple data units, as well as identifiers and auxiliary information. The auxiliary information is used to characterize the first sample data. The identifiers are used to identify the auxiliary information.

[0105] In an embodiment, for the case where the first sample data is the content of a blog post, the auxiliary information may include at least one of the following: the content of the blog post, the identifier of the blog post, the identifier of the blogger of the blog post, the number of followers of the blogger, the whitelist type, the verification type, the verification reason, the tag of the blog post, and the tag of the blogger. Each type of auxiliary information corresponds to a unique identifier. In an example, the first sample data may be: {"mid":"4922274538586731"; "uid":"2085202803"; "user_name": "Yi Nan Asks - Emotion and Marriage"; "blog": "The second of the six constellations with the best temper: Capricorn. Capricorn has a strong mindset, but also has a good temper that friends like. They will not deliberately look for trouble with someone, always imagine that they are full of sense of justice, and are very friendly to friends, even people they know, but it does not mean that they do not have a bad temper, they just know how to control themselves better. In addition, Capricorn belongs to the optimistic school, always has an excited expression, giving people a sense of closeness."; "firsttags": "Constellation Numerology"; "followers_count": 11845; "verified_type": 0; "verified_reason": "Constellation Numerology Blogger"}. "4922274538586731" is the number of the blog post, and "mid" is the identifier corresponding to the identifier of the blog post. "2085202803" is the number of the blogger, and "uid" is the identifier corresponding to the identifier of the blogger. "Yi Nan Asks - Emotion and Marriage" is the name of the blogger, and "user_name" is the identifier corresponding to the name of the blogger. "The six constellations with the best temper... giving people a sense of closeness." is the content of the blog post and contains a plurality of data units, and "blog" is the identifier corresponding to the content of the blog post. "Constellation Numerology" is the primary tag of the blog post, and "firsttags" is the identifier corresponding to the primary tag of the blog post. "11845" is the number of followers, and "followers_count" is the identifier corresponding to the tag of the blog post. "0" is the verification type, and "verified_type" is the identifier corresponding to the verification type. "Constellation Numerology Blogger" is the verification reason, and "verified_reason" is the identifier corresponding to the verification reason. It can be understood that the auxiliary information may also include other content and may correspond to other identifiers, which is not specifically limited in the embodiments of the present application.

[0106] In step S420, a plurality of data units in the first sample data are input into the LLaMA model to obtain a feature quantity.

[0107] Step S420 in this embodiment is substantially the same as that in Figure 2 step S220 in the embodiment shown, and the same content will not be repeated here.

[0108] In step S430, the LLaMA model is trained based on the feature values ​​until the LLaMA model converges.

[0109] Step S430 in this embodiment and Figure 2 Step S230 in the illustrated embodiment is the same and will not be described again here.

[0110] In step S440, the identifier is added to the identifier list.

[0111] A tokenizer can be set before or within the LLaMA model. The tokenizer can be used to divide the initial sample data. In this way, the initial sample data can be divided into multiple data units, as well as identifiers and auxiliary information.

[0112] In one embodiment, an identifier list is provided inside or outside the tokenizer. Identifiers related to auxiliary information can be stored in the identifier list. The identifier list enables the identification of auxiliary information in the input data. The tokenizer can identify and segment the identifiers in the first sample data according to the identifier list. Each identifier has a corresponding identifier number (token_id). For an identifier present in the identifier list, the tokenizer can treat that identifier as a whole to obtain its corresponding identifier number.

[0113] Here, the list of identifiers can be maintained based on the first sample data. Specifically, operations such as adding, deleting, and modifying identifiers can be performed on the list.

[0114] In one embodiment, the identifier may include, for example: <full text>, <blogger name>, <follower count level>, <whitelist type>, <authentication type>, <authentication reason>, and <first-level tag>. In one embodiment, the identifier may include, for example: <blog> 、 <uid>、<followers_count>、<white_list>、<verified_type>、<verified_reason>、 <firsttags>Of course, the identifier can also be expressed in other ways, and this application does not specifically limit this.

[0115] In one embodiment, if a new identifier is obtained based on the first sample data, the new identifier can be added to the identifier list. In one embodiment, if an identifier in the identifier list is not identified within a certain period of time, the identifier can be deleted from the identifier list. In one embodiment, if the same type of auxiliary information corresponds to different identifiers in different first sample data, an identifier can be used to replace an existing identifier in the identifier list.

[0116] In one embodiment, step S440 can be implemented using a word segmenter. The word segmenter can be trained based on the first sample data. During training, the word segmenter can add identifiers to an identifier list. In one embodiment, step S440 can be implemented manually. Specifically, a worker can directly add identifiers to the identifier list.

[0117] It should be noted that step S440 can be executed before, simultaneously with, or after step S420. Step S440 can also be executed before, simultaneously with, or after step S430; this embodiment of the application does not specifically limit this.

[0118] By following the steps S410 to S440 above, the trained content generation model can be obtained.

[0119] In this embodiment, an identifier list can be set in the LLaMA model to store custom identifiers. When generating content based on the LLaMA model, auxiliary information in the input data can be identified according to the identifier list and directly added to the generated content. In this way, the generated content and auxiliary information in the push notification can be distinguished, thereby increasing the probability of the push notification being accepted.

[0120] Figure 5 This is a flowchart illustrating the content generation method in an embodiment of this application. For example... Figure 5 As shown, the content generation method of this application embodiment may include steps S510 to S530.

[0121] In step S510, the first data is obtained.

[0122] Here, the first data refers to the data of the blog posts to be recommended. In some cases, the format of the first data may be exactly the same as or partially the same as the first sample data, which will not be elaborated here.

[0123] In one embodiment, for a Weibo scenario, the first data can be the Weibo post with the highest number of views on that day, or it can be the latest Weibo post from a blogger followed by the user. In one embodiment, for a news scenario, the first data can be news articles related to the day's trending news. The content of the first data is not limited in this embodiment.

[0124] In some embodiments, the first data may include multiple data units. In one example, the multiple data units may include the blog post content of the blog post to be recommended.

[0125] In step S520, multiple data unit input contents are used to generate a model and obtain feature quantities.

[0126] In one embodiment, the content generation model may include an encoding unit. The encoding unit is used to perform rotational position encoding on the feature vectors of multiple data units. The distance between two data units is a first distance. The angle difference between the rotation angles of the feature vectors of two data units after rotational position encoding is a first angle difference. The first distance and the first angle difference satisfy a monotonically increasing relationship. It should be noted that the structure and function of the encoding unit in the content generation model can be found in [reference needed]. Figure 2 and Figure 4 The LLaMA model in this context will not be elaborated upon here.

[0127] In one embodiment, the feature vector corresponding to one of the two data units may be a Q vector, and the feature vector corresponding to the other data unit may be a K vector.

[0128] In step S530, recommended content is determined based on the feature values.

[0129] Here, after obtaining the feature values ​​of multiple data units, recommended content for the blog posts to be recommended can be generated based on these feature values. The recommended content may include the title and / or summary.

[0130] In one embodiment, the determined recommended content may include multiple prediction data units. Each prediction data unit may be a word or a symbol. In this case, a feature quantity can be obtained for each prediction data unit. The feature quantity can be used to indicate the probability that the corresponding prediction data unit is a word in the vocabulary.

[0131] In one embodiment, each predicted data unit in the recommended content can be a word or symbol corresponding to the highest probability value among the corresponding feature quantities. In this way, the recommended content can be determined in step S530.

[0132] In one embodiment, the content generation method of this application embodiment may further include step S540. In step S540, auxiliary information from the first data is added to the recommended content.

[0133] In one embodiment, the first data may include multiple data units, as well as identifiers and auxiliary information. After obtaining recommended content based on the multiple data units, the auxiliary information from the first data can be added to the recommended content.

[0134] In one embodiment, step S540 can be implemented by: determining an identifier based on the first data; determining auxiliary information in the first data based on the identifier; and adding the auxiliary information to the recommended content.

[0135] For example, a word segmenter can be used to divide the first data into multiple data units, identifiers, and auxiliary information. Specifically, during the process of dividing the first data, identifiers can be identified. Based on the identifiers, auxiliary information can be determined.

[0136] In one example, the identifiers in the first data can be identified from the list of identifiers.

[0137] In this embodiment, when generating content based on the content generation model, auxiliary information in the input data can be identified and directly added to the generated recommended content. This distinguishes between the generated content and auxiliary information in the push notifications, thereby improving the quality of the push notifications and their acceptance rate.

[0138] It should be noted that the model training method and content generation method provided in this application embodiment can be applied not only to the LLaMA model, but also to other derived models based on the LLaMA model. This application embodiment does not make specific limitations in this regard.

[0139] Based on the same inventive concept, embodiments of this application provide a model training device. Figure 6 This is a schematic diagram of the model training device in an embodiment of this application. Figure 6 As shown, the model training device 600 includes an acquisition module 610, a generation module 620, and a training module 630. The acquisition module 610 is configured to acquire first sample data. The first sample data includes multiple data units. The generation module 620 is configured to input the first sample data into an LLaMA model to obtain feature quantities. The LLaMA model includes encoding units. The encoding units are used to perform rotational position encoding on the feature vectors of the multiple data units. The distance between two data units is a first distance. The angle difference between the rotation angles of the feature vectors of two data units after rotational position encoding is a first angle difference. The first distance and the first angle difference satisfy a monotonically increasing relationship. The training module 630 is configured to train the LLaMA model based on the feature quantities until the LLaMA model converges, obtaining a trained content generation model.

[0140] In some possible implementations, the encoding unit may include a rotation matrix. The rotation matrix is ​​used for encoding the rotational positions of the feature vectors of multiple data units. The rotation matrix can be:

[0141]

[0142] Among them, A i Let N be the rotation matrix, N1 be the size of the rotation matrix, N1 be an even number and greater than 1, i be a positive integer not greater than N, and N be the number of data units in the first sample data.

[0143] The angle parameter of the rotation matrix can be:

[0144]

[0145] in, Let N be the angle parameter, N2 be the maximum number of data units in the first sample data, and t be an even number with a value ranging from 0 to N1-2.

[0146] In some possible implementations, the relative rotation matrix, which is composed of the rotation matrices corresponding to the eigenvectors of the two data units, can be:

[0147]

[0148] Among them, A i,j Let N represent the relative rotation matrix, where i and j are the positions of two data units in multiple data units, and i and j are both positive integers not greater than N.

[0149] In some possible implementations, the feature vector corresponding to one of the two data units may be a Q vector, and the feature vector corresponding to the other data unit may be a K vector.

[0150] In some possible implementations, the first sample data may further include identifiers and auxiliary information. The auxiliary information is used to characterize the first sample data. The identifiers are used to identify the auxiliary information.

[0151] In some possible implementations, the model training apparatus 600 described above may further include a storage module 640. The storage module 640 is configured to add identifiers to an identifier list. The identifier list contains custom identifiers.

[0152] In some possible implementations, multiple data units may include blog post content. Supporting information may include at least one of the following: blog post identifier, blogger identifier, blogger's follower count, whitelist type, authentication type, authentication reason, blog post tags, and blogger tags.

[0153] Figure 7 This is a schematic diagram of the structure of the content generation device in an embodiment of this application. For example... Figure 7 As shown, the content generation device 700 may include an acquisition module 710, a generation module 720, and a determination module 730. The acquisition module 710 is configured to acquire first data of the blog post to be recommended. The first data includes multiple data units. The generation module 720 is configured to input the multiple data units into a content generation model to obtain feature values. The determination module 730 is configured to determine the recommended content corresponding to the blog post to be recommended based on the feature values.

[0154] In some possible implementations, the first data may further include an identifier and auxiliary information. The auxiliary information is used to characterize the blog post to be recommended. The identifier is used to identify the auxiliary information. The method described above may also include an auxiliary information module 740. The auxiliary information module 740 is configured to: determine an identifier based on the first data; determine auxiliary information in the first data based on the identifier; and add the auxiliary information to the recommended content.

[0155] In some possible implementations, multiple data units may include the blog post content of the post to be recommended. Auxiliary information may include at least one of the following: the identifier of the post to be recommended, the identifier of the blogger of the post to be recommended, the number of followers of the blogger, whitelist type, authentication type, authentication reason, tags of the post to be recommended, and tags of the blogger.

[0156] It should be noted that the technical details of the model training device and content generation device in the embodiments of this application can be found in the detailed description of the model training method and content generation method described above, and will not be repeated here.

[0157] Based on the same inventive concept, this application provides an electronic device. Figure 8 This is a structural diagram of the electronic device in an embodiment of this application. For example... Figure 8 As shown, the electronic device 800 includes a memory 801 and a processor 802. The memory 801 is used to store executable instructions. When the processor 802 executes the executable instructions stored in the memory, it implements at least one of the model training method and content generation method of the embodiments of this application.

[0158] Based on the same inventive concept, embodiments of this application provide a computer program product or computer program. The computer program product or computer program includes computer instructions. These computer instructions are stored in a computer storage medium. The processor of a computer device reads the computer instructions from the computer storage medium and executes the computer instructions, causing the computer device to perform at least one of the model training method and content generation method of embodiments of this application.

[0159] Based on the same inventive concept, embodiments of this application provide a storage medium storing executable instructions. The storage medium stores the executable instructions. When the executable instructions are executed by a processor, the processor will execute at least one of the model training method and content generation method of embodiments of this application.

[0160] In some embodiments, the computer storage medium may be a non-volatile computer storage medium, such as a memory like FRAM, ROM, PROM, EPROM, EEPROM, flash memory, magnetic surface memory, optical disk, or CD-ROM; or it may be a variety of devices including one or any combination of the above-mentioned memories.

[0161] In some embodiments, executable instructions may take the form of a program, software, software module, script, or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a standalone program or as a module, component, subroutine, or other unit suitable for use in a computing environment.

[0162] As an example, executable instructions may, but do not necessarily, correspond to files in a file system. They may be stored as part of a file that holds other programs or data, for example, in one or more scripts in a Hyper Text Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple collaborating files (e.g., a file that stores one or more modules, subroutines, or code sections).

[0163] As an example, executable instructions can be deployed to execute on a single computing device, or on multiple computing devices located in one location, or on multiple computing devices distributed across multiple locations and interconnected via a communication network.

[0164] The above description is merely an embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, and improvements made within the spirit and scope of this application are included within the scope of protection of this application.< / firsttags> < / uid> < / blog>

Claims

1. A content generation method, characterized in that, The method includes: The process involves obtaining first data for a blog post to be recommended, wherein the first data includes multiple data units, identifiers, and auxiliary information; the multiple data units include the blog post content of the blog post to be recommended; the identifiers are used to identify the auxiliary information; the auxiliary information is used to characterize the blog post to be recommended, and the auxiliary information includes at least one of the following: the identifier of the blog post to be recommended, the identifier of the blogger of the blog post to be recommended, the number of followers of the blogger, the whitelist type, the authentication type, the authentication reason, the tags of the blog post to be recommended, and the tags of the blogger; The multiple data units are input into the content to generate a model and obtain feature quantities, wherein the feature quantities are used to indicate the probability that the corresponding prediction data unit is a word in the vocabulary; Based on the aforementioned feature values, the recommended content corresponding to the blog post to be recommended is determined; Based on the first data, the identifier symbol is determined; The auxiliary information in the first data is determined based on the identification symbol; Add the auxiliary information to the recommended content; The content generation model is obtained using the following model training method: Acquire first sample data, wherein the first sample data includes the plurality of data units; The first sample data is input into the improved LLaMA model to obtain feature quantities. The improved LLaMA model includes an encoding unit, which is used to perform rotation position encoding on the feature vectors of the plurality of data units. The distance between two data units in the plurality of data units is the first distance. The angle difference between the rotation angles of the feature vectors of the two data units after rotation position encoding is the first angle difference. The first distance and the first angle difference satisfy a monotonically increasing relationship. The improved LLaMA model is trained based on the aforementioned features until it converges, thus obtaining the trained content generation model. The encoding unit includes a rotation matrix, which is used for encoding the rotation position of the feature vectors of the plurality of data units; The rotation matrix is: Among them, A i Let N1 represent the rotation matrix, N1 be the size of the rotation matrix, N1 be an even number and N1 be greater than 1, i be a positive integer not greater than N, and N be the number of the plurality of data units in the first sample data; The angle parameters of the rotation matrix are: in, The angle parameter is N2, which is the maximum number of data units in the first sample data, and t is an even number with a value ranging from 0 to N1-2. The improved LLaMA model is an LLaMA model with the rotation matrix and the angle parameters.

2. The method according to claim 1, characterized in that, The relative rotation matrix, formed by the rotation matrices corresponding to the eigenvectors of the two data units, is as follows: Among them, A i,j Let N represent the relative rotation matrix, where i and j are the positions of the two data units in the plurality of data units, and i and j are both positive integers not greater than N.

3. The method according to claim 1 or 2, characterized in that, The feature vector corresponding to one of the two data units is the Q vector, and the feature vector corresponding to the other data unit is the K vector.

4. A content generation device, characterized in that, The device includes: The acquisition module is configured to acquire first data of the blog post to be recommended, wherein the first data includes multiple data units, identifiers, and auxiliary information; the multiple data units include the blog post content of the blog post to be recommended; the identifiers are used to identify the auxiliary information; the auxiliary information is used to characterize the blog post to be recommended, and the auxiliary information includes at least one of the following: the identifier of the blog post to be recommended, the identifier of the blogger of the blog post to be recommended, the number of followers of the blogger, the whitelist type, the authentication type, the authentication reason, the tags of the blog post to be recommended, and the tags of the blogger; The generation module is configured to input the multiple data units into the content to generate a model and obtain feature quantities, wherein the feature quantities are used to indicate the probability that the corresponding predicted data unit is a word in the vocabulary; The determination module is configured to determine the recommended content corresponding to the blog post to be recommended based on the feature quantity; The auxiliary information module is configured to determine the identifier based on the first data; determine the auxiliary information in the first data according to the identifier; and add the auxiliary information to the recommended content. The generation module is further configured as follows: Acquire first sample data, wherein the first sample data includes the plurality of data units; The first sample data is input into the improved LLaMA model to obtain feature quantities. The improved LLaMA model includes an encoding unit, which is used to perform rotation position encoding on the feature vectors of the plurality of data units. The distance between two data units in the plurality of data units is the first distance. The angle difference between the rotation angles of the feature vectors of the two data units after rotation position encoding is the first angle difference. The first distance and the first angle difference satisfy a monotonically increasing relationship. The improved LLaMA model is trained based on the aforementioned features until it converges, thus obtaining the trained content generation model. The encoding unit includes a rotation matrix, which is used for encoding the rotation position of the feature vectors of the plurality of data units; The rotation matrix is: Among them, A i Let N1 represent the rotation matrix, N1 be the size of the rotation matrix, N1 be an even number and N1 be greater than 1, i be a positive integer not greater than N, and N be the number of the plurality of data units in the first sample data; The angle parameters of the rotation matrix are: in, The angle parameter is N2, which is the maximum number of data units in the first sample data, and t is an even number with a value ranging from 0 to N1-2. The improved LLaMA model is an LLaMA model with the rotation matrix and the angle parameters.

5. An electronic device, characterized in that, The electronic device includes: Memory, used to store executable instructions; A processor, when executing executable instructions stored in the memory, implements the method as described in any one of claims 1 to 3.

6. A storage medium having executable instructions stored thereon, characterized in that, When the executable instructions are executed by the processor, they implement the method as described in any one of claims 1 to 3.

Citation Information

Patent Citations

  • Knowledge graph representation learning method based on distance and angle constraints

    CN112528047A

  • Information processing method and device, robot and storage medium

    CN117033598A