Text generation method, network training method, device, equipment and storage medium

By constraining the hidden space of sample font style information to be normally distributed, the font style encoding network and text generation network are used to generate target text, which solves the problems of large resource consumption and low generation quality in the existing technology, and achieves more efficient text generation.

CN114626335BActive Publication Date: 2025-01-14TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210144287.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-02-17
Publication Date
2025-01-14
Estimated Expiration
2042-02-17

AI Technical Summary

Technical Problem

The prior art consumes a lot of system resources during the text generation process, and is prone to missing strokes or sticking strokes, resulting in low generation quality.

Method used

By obtaining candidate texts of different font styles, using font style encoding networks and text generation networks for training, the hidden space of sample font style information is constrained to be normal distribution, thereby generating target text, compressing font style information, and narrowing the spacing between different font styles , avoid network interruptions and improve generation quality.

Benefits of technology

It reduces the consumption of system resources by the target text generation process, improves the generation quality, and avoids the problem of missing strokes or sticking.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114626335B_ABST
    Figure CN114626335B_ABST
Patent Text Reader

Abstract

The present application provides a text generation method, a network training method, device, equipment and storage medium for text generation, which can be applied to various scenarios such as cloud technology, artificial intelligence, smart transportation, and assisted driving. The text generation method includes: obtaining at least two candidate texts with different font style information from a set of texts to be processed; generating font style information corresponding to at least two candidate texts based on a font style encoding network; generating target text corresponding to the font style information and text content information based on a text generation network; wherein the font style encoding network and the text generation network are obtained by training a preset neural network for text generation, and the latent space of the sample font style information used in the text generation training process is constrained to be normally distributed. The embodiments of the present application can improve the generation quality of the target text and reduce the generation cost of the target text.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the field of computer technology, and specifically relates to a text generation method, a network training method, a device, a equipment and a storage medium. Background Art

[0002] In the related art, the style representation of a certain font is usually learned from a subset of characters in the font, and then a whole set of characters corresponding to the new font is generated.

[0003] However, the related technology requires pre-setting some texts under the new font, and then inputting these texts into the text generation model to learn the style features, and then obtaining other text results from the model, and finally obtaining the whole set of texts corresponding to the new font. The text generation process consumes more system resources, resulting in a high cost of text generation. In addition, the text generation model in the related technology is prone to stroke missing or stroke adhesion problems, resulting in low quality of text generation. Summary of the invention

[0004] In order to solve the above technical problems, the present application provides a text generation method, a network training method, an apparatus, a device and a storage medium.

[0005] On the one hand, the present application proposes a text generation method, the method comprising:

[0006] Obtain at least two candidate characters with different font style information from the character set to be processed;

[0007] Generate font style information corresponding to each of the at least two candidate characters based on a font style encoding network;

[0008] Based on the text generation network, generating target text corresponding to the font style information and text content information; the text content information represents the content of the text in the to-be-processed text set;

[0009] The font style encoding network and the text generation network are obtained by training a preset neural network for text generation, and the latent space of sample font style information used in the text generation training process is constrained to be normally distributed.

[0010] On the other hand, the present application provides a network training method for text generation, the method comprising:

[0011] Extracting a first sample text and a second sample text from the sample text set;

[0012] Based on the sample font style information of the first sample text and the sample text content information of the second sample text, a preset neural network is trained for text generation. During the text generation training process, the latent space of the sample font style information is constrained to be normally distributed to obtain a font style encoding network and a text generation network.

[0013] On the other hand, an embodiment of the present application provides a text generation device, the device comprising:

[0014] A text acquisition module, used for acquiring at least two candidate texts with different font style information from the text set to be processed;

[0015] A font style information generating module, used for generating font style information corresponding to the at least two candidate characters respectively based on a font style encoding network;

[0016] A target text generation module, for generating target text corresponding to the font style information and text content information based on a text generation network; the text content information represents the content of the text in the to-be-processed text set;

[0017] The font style encoding network and the text generation network are obtained by training a preset neural network for text generation, and the latent space of sample font style information used in the text generation training process is constrained to be normally distributed.

[0018] On the other hand, the present application provides a network training device for text generation, the device comprising:

[0019] A sample text acquisition module, used to extract a first sample text and a second sample text from a sample text set;

[0020] A training module is used to perform text generation training on a preset neural network based on the sample font style information of the first sample text and the sample text content information of the second sample text. During the text generation training process, the latent space of the sample font style information is constrained to be normally distributed to obtain a font style encoding network and a text generation network.

[0021] On the other hand, the present application proposes an electronic device, which includes a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or at least one program is loaded and executed by the processor to implement the text generation method or the network training method for text generation as described above.

[0022] On the other hand, the present application proposes a computer-readable storage medium, which stores at least one instruction or at least one program, and the at least one instruction or the at least one program is loaded and executed by a processor to implement the text generation method or the network training method for text generation as described above.

[0023] On the other hand, the present application proposes a computer program product, including a computer program, which, when executed by a processor, implements the text generation method or the network training method for text generation as described above.

[0024] The text generation method, network training method, device, equipment and storage medium proposed in the embodiments of the present application use a trained font style encoding network to generate font style information corresponding to each of the at least two candidate texts, and use a trained text generation network to generate a target text corresponding to the font style information and text content information. Since the latent space of the sample font style information is constrained to be normally distributed during the training process, the font style information is compressed, the distance between different font style information is shortened, and the change of the style latent space is smoother, avoiding the network from encountering discontinuities, thereby improving the generation quality of the target text; in addition, the use of the trained font style encoding network and the text generation network can also reduce the consumption of system resources in the target text generation process, thereby reducing the generation cost of the target text. BRIEF DESCRIPTION OF THE DRAWINGS

[0025] In order to more clearly illustrate the technical solutions and advantages in the embodiments of the present application or the prior art, the drawings required for use in the embodiments or the prior art descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0026] Figure 1 It is a schematic diagram of an implementation environment of a text generation method according to an exemplary embodiment.

[0027] Figure 2 It is a flowchart of a method for generating text according to an exemplary embodiment.

[0028] Figure 3 The figure is a flow chart showing a method of standardizing style and content according to an exemplary embodiment.

[0029] Figure 4 The present invention is a flowchart of a network training method for text generation according to an exemplary embodiment.

[0030] Figure 5is a schematic diagram of a preset neural network according to an exemplary embodiment.

[0031] Figure 6 It is a flowchart showing a trained lattice encoding network and a text generation network according to an exemplary embodiment.

[0032] Figure 7 The figure is a schematic diagram showing a method of obtaining sample font style information according to an exemplary embodiment.

[0033] Figure 8 The figure is a schematic diagram showing a method of standardizing sample font style information and sample text content information according to an exemplary embodiment.

[0034] Fig. 9 It is a schematic diagram of a target text generated by the text generation method according to an embodiment of the present application, according to an exemplary embodiment.

[0035] Fig.10 is a comparison diagram of fusion effects shown according to an exemplary embodiment.

[0036] Fig.11 It is a schematic diagram of similar fonts obtained by detecting the font of a target text through a font similarity detection model according to an exemplary embodiment.

[0037] Fig.12 The invention is a text generating device according to an exemplary embodiment.

[0038] Fig.13 The invention discloses a network training device for text generation according to an exemplary embodiment.

[0039] Fig.14 It is a hardware structure block diagram of a server for text generation or network training of text generation provided in an embodiment of the present application. DETAILED DESCRIPTION

[0040] Artificial Intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results. In other words, artificial intelligence is a comprehensive technology in computer science that attempts to understand the essence of intelligence and produce a new intelligent machine that can respond in a similar way to human intelligence. Artificial intelligence is to study the design principles and implementation methods of various intelligent machines so that machines have the functions of perception, reasoning and decision-making.

[0041] Artificial intelligence technology is a comprehensive discipline that covers a wide range of fields, including both hardware-level and software-level technologies. The basic technologies of artificial intelligence generally include sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics and other technologies. Artificial intelligence software technology mainly includes computer vision technology, speech processing technology, natural language processing technology, and machine learning / deep learning.

[0042] Specifically, embodiments of the present application relate to artificial neural network technology in deep learning.

[0043] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.

[0044] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or server that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0045] Figure 1 FIG. 1 is a schematic diagram of an implementation environment of a text generation method according to an exemplary embodiment. Figure 1 As shown, the implementation environment may include at least a terminal 01 and a server 02. The terminal 01 and the server 02 may be directly or indirectly connected via wired or wireless communication, and this application does not impose any limitation thereto.

[0046] Specifically, the terminal can be used to collect a text set to be processed and a sample text set. Optionally, the terminal 01 can include but is not limited to a mobile phone, a computer, an intelligent voice interaction device, a smart home appliance, a vehicle terminal, an aircraft, etc. The embodiment of the present application can be applied to various scenarios, including but not limited to cloud technology, artificial intelligence, smart transportation, assisted driving, etc.

[0047] Specifically, the server 02 can be used to train the font style encoding network and the text generation network, and generate the target text based on the font style encoding network and the text generation network. Optionally, the server 02 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms.

[0048] It should be noted that Figure 1 This is just an example. In other scenarios, other implementation environments may also be included. For example, the implementation environment may include a terminal, through which a font style encoding network and a text generation network are obtained through terminal training, and a target text is generated based on the font style encoding network and the text generation network.

[0049] Figure 2 is a flowchart of a method for generating text according to an exemplary embodiment. The method can be used for Figure 1 In the implementation environment of the embodiment. This specification provides the method operation steps as described in the embodiment or flowchart, but may include more or fewer operation steps based on routine or non-creative work. The order of steps listed in the embodiment is only one way of executing the steps among many steps, and does not represent the only execution order. When the actual system or server product is executed, it can be executed in sequence or in parallel (for example, in a parallel processor or multi-threaded processing environment) according to the method shown in the embodiment or the drawings. Specifically, Figure 2 As shown, the method may include:

[0050] S101. Obtain at least two candidate characters with different font style information from a set of characters to be processed.

[0051] Specifically, the font style information may include, but is not limited to: Kaiti, Songti, Founder Cartoon, Heiti, Huawen Xingkai, Founder Taoti, etc. Optionally, the to-be-processed text set may include all texts of various font style information, such as all Kaiti texts, all Songti texts, all Founder Cartoon, etc.

[0052] In the embodiment of the present application, a variety of methods can be used to obtain at least two candidate characters with different font style information from the set of characters to be processed, which are not specifically limited here.

[0053] In one method, the characters in the processed character set can be classified according to the font style information to obtain multiple font style information categories, each of which corresponds to multiple characters. At least two candidate font style information categories can be determined from the multiple font style information categories, and one character can be extracted from the characters corresponding to the at least two candidate font style information categories to obtain at least two candidate characters. For example, a Kaiti category and a Songti category can be determined from the multiple font style information categories, the Kaiti category corresponds to multiple characters, the Songti category corresponds to multiple characters, one character is extracted from the multiple characters corresponding to the Kaiti category, and one character is extracted from the multiple characters corresponding to the Songti category to obtain at least two candidate characters.

[0054] In another manner, a preset number of characters can be extracted from the characters corresponding to the at least two candidate font style information categories to obtain at least two candidate characters. For example, a Kaiti category and a Songti category can be determined from multiple font style information categories, the Kaiti category corresponds to multiple characters, the Songti category corresponds to multiple characters, a preset number of characters are extracted from the multiple characters corresponding to the Kaiti category, and a preset number of characters are extracted from the multiple characters corresponding to the Kaiti category to obtain at least two candidate characters.

[0055] S103. Generate font style information corresponding to the at least two candidate characters based on the font style encoding network.

[0056] S105. Based on the text generation network, generate target text corresponding to the above-mentioned font style information and text content information; the above-mentioned text content information represents the content of the text in the above-mentioned text set to be processed.

[0057] The font style encoding network and the text generation network are obtained by training a preset neural network for text generation, and the latent space of the sample font style information used in the text generation training process is constrained to be normally distributed.

[0058] Exemplarily, the text content information may be spatial information of the text content, for example, the stroke structure of the text.

[0059] Exemplarily, the latent space may refer to the space where latent variables (e.g., noise Z) are located, and the latent space constraints may be understood as constraints on latent vectors in the latent space. By constraining the latent space of sample font style information during the training process, text with better quality and effect can be generated during the text generation process.

[0060] In a specific embodiment, in the above step S103, at least two candidate characters may be input into a pre-trained font style encoding network, and the font style encoding network may be used to extract features of the at least two candidate characters to obtain font style information corresponding to the at least two candidate characters. For example, the font style information corresponding to the at least two candidate characters extracted by the pre-trained encoding network may be Kaiti and Songti.

[0061] Optionally, the embodiment of the present application may generate the font style information corresponding to the at least two candidate characters in a variety of ways, which are not specifically limited here.

[0062] In one embodiment, in the above step S103, the above-mentioned generation of font style information corresponding to each of the above-mentioned at least two candidate characters based on the font style encoding network may include: mapping the above-mentioned at least two candidate characters to the above-mentioned normal distribution based on the above-mentioned font style encoding network to obtain the font style information corresponding to each of the above-mentioned at least two candidate characters.

[0063] Since the latent space of the sample font style information is constrained to be a normal distribution during the above-mentioned text generation training process, after at least two candidate texts are input into the font style encoding network, the font style encoding network can map the at least two candidate texts to the normal distribution, extract the style feature vectors corresponding to the at least two candidate texts from the normal distribution, and extract the style feature vectors corresponding to the at least two candidate texts, and obtain the font style information corresponding to the at least two candidate texts. Since the latent space of the sample font style information is constrained to be a normal distribution, the font style information is compressed during the font style information extraction process, and the distance between the different font style information corresponding to the at least two candidate texts is shortened, so that the change of the style latent space is smoother, and the network is prevented from encountering discontinuities, thereby improving the generation quality of the font style information, and then improving the generation quality of the target text.

[0064] In a specific embodiment, in the above step S105, the content of the text can be extracted from the text set to be processed as the text content information, and the text content information and the font style information are input into a pre-trained text generation network to generate the target text. The text generation network can include two branches: a style branch and a content branch. The style branch input is the font style information obtained by the font style encoding network, and the content branch input is the text content information.

[0065] In one method, the text content information of each character can be extracted from the to-be-processed text set in turn, and the text content information of each character can be traversed in turn to obtain the target character corresponding to the text content information and font style information of each character.

[0066] In another way, the text content information of all the characters can be extracted from the set of characters to be processed, and the text content information of all the characters can be traversed in parallel to obtain the target characters corresponding to the text content information and font style information of all the characters.

[0067] In an optional embodiment, the method may further include: calculating an average value of the font style information based on the font style encoding network to obtain target font style information.

[0068] Correspondingly, in the above step S105, generating the target text corresponding to the above font style information and text content information based on the text generation network may include: generating the target text corresponding to the above target font style information and text content information based on the above text generation network.

[0069] Specifically, since at least two candidate characters are input into the font style encoding network, the font style encoding network will output a font style information for each candidate character. Therefore, the mean of the font style information corresponding to at least two candidate characters can be obtained to obtain the target font style information. The target font style information can be understood as a new style feature, that is, the target character style feature is different from the font style information corresponding to the characters in the character set to be processed. Exemplarily, since characters can be processed as images, and the style information of images is usually represented by the mean and variance, the above-mentioned mean of the font style information corresponding to at least two candidate characters can be understood as the mean of the images corresponding to at least two candidate characters.

[0070] Accordingly, after obtaining the target font style information, the target font style information and the text content information can be input into the text generation network to obtain the target text corresponding to the text content information and the target font style information. In an embodiment of the present application, by calculating the average value of the font style information corresponding to at least two candidate texts, a new style feature (i.e., target font style information) can be obtained, and the accuracy of generating the target font style information is relatively high. Inputting the target font style information and text content information with a relatively high accuracy into the text generation network can improve the generation quality of the target text; in addition, a whole set of new text (i.e., target text) corresponding to the target font style information can be generated through the text generation network, without pre-setting some text under a new font, which can reduce the consumption of system resources by the target text generation process, thereby reducing the generation cost of the target text.

[0071] Figure 3 FIG. 1 is a flow chart showing a method of standardizing style and content according to an exemplary embodiment. Figure 3As shown, in an optional embodiment, the above method may further include:

[0072] S201. Decouple the above font style information.

[0073] S203. Standardize the decoupled font style information to obtain standard font style information.

[0074] S205. Standardize the above text content information to obtain standard text content information.

[0075] Accordingly, in the above step S105, the above generating target text corresponding to the above font style information and text content information based on the text generation network may include:

[0076] Based on the above-mentioned text generation network, the above-mentioned target text corresponding to the above-mentioned standard font style information and the above-mentioned standard text content information is generated.

[0077] In an optional embodiment, the structure of the text generation network can be a SPADE+AdaIN structure. SPADE is a generation model that converts a segmentation map into a real scene map. As a backbone network, it can better preserve the structural information of the text. AdaIN is the abbreviation of Adaptive Instance Normalization, and its Chinese name is Adaptive Instance Normalization.

[0078] Exemplarily, in the above steps S201-S203, the font style information can be input into a multi-layer perceptron (MLP) for decoupling, and the decoupled font style information can be standardized by AdaIN to obtain the standardized standard font style information, that is, the decoupled style is input into each layer of the network by AdaIN, and the style of the generated image is controlled by controlling the feature statistical information. Among them, MLP is an artificial neural network with a forward structure. Exemplarily, decoupling can refer to: decoupling of the style itself, such as stroke thickness, pen tip, etc.

[0079] The font style information in the embodiment of the present application is decoupled after multiple layers of fully connected layers and then sent to each layer of the network. In this way, the text generation network can extract font style information from multiple semantic levels.

[0080] In text generation, the content branch retains the stroke structure of the text. The stroke structure of the text (i.e., the text content information) is a key factor. Exemplarily, in the above step S205, the stroke structure of the text can be standardized in the form of spatial adaptive instance normalization (SpatialAdaptiveNormalization, SpatialAdaIN) to obtain standard text content information, that is, the stroke structure of the text is inserted into the text generation network in the form of SpatialAdaIN. In this way, the stroke structure of the text is better retained, that is, the spatial information of the original segmentation is retained), thereby improving the generation quality of the target text.

[0081] Figure 4 FIG. 1 is a flowchart of a network training method for text generation according to an exemplary embodiment. Figure 4 As shown, the method may include:

[0082] S301. Extract a first sample text and a second sample text from a sample text set.

[0083] Optionally, the first sample text may be a sample text set or a single text, and the second sample text may also be a sample text set or a single text.

[0084] For example, for any text x in the sample text set ij , which contains the style attribute S i ∈S and content attribute C j ∈c. In order to represent a style, we can select the sample text with style S i Take K characters from the font to form a reference set of this style That is, the first sample text. Among them, d s is the dimension of style embedding, and J is a positive integer greater than or equal to 1.

[0085] For example, to represent the content attribute C j , some words can be taken from the sample text set to form a content reference set That is the second sample text.

[0086] If texts of different styles but the same content are selected as the content reference set, the difficulty of network learning content will increase. This is because texts of different styles have great differences in position and stroke form, and it is difficult for the network to abstract the correct stroke structure from them. Therefore, in an exemplary embodiment, in order to reduce the difficulty of network learning content, sample text with Song font style information can be selected from the sample text set as the second sample text. Since Song font is a standard font, it is conducive to the model learning font structure. Furthermore, in order to further reduce the difficulty of network learning content, a single Song font can be selected from the sample text set, that is, L=1, The text in is used as the second sample text.

[0087] S303. Based on the sample font style information of the above-mentioned first sample text and the sample text content information of the above-mentioned second sample text, the preset neural network is trained for text generation. During the above-mentioned text generation training process, the latent space of the above-mentioned sample font style information is constrained to be normally distributed, so as to obtain a font style encoding network and a text generation network.

[0088] In an embodiment of the present application, the sample font style information of the first sample text and the sample text content information of the second sample text can be input into a preset neural network for text generation training, and during the text generation training process, the latent space of the sample font style information is constrained to be normally distributed, thereby obtaining a font style encoding network and a text generation network. Since the latent space of the sample font style information is constrained to be normally distributed during the training process, the font style information is compressed, the spacing between different font style information is shortened, and the change of the style latent space is smoother, avoiding the network from encountering discontinuities, and improving the training accuracy of the font style encoding network and the text generation network; in addition, based on the sample font style information of the first sample text and the sample text content information of the second sample text, the preset neural network is trained for text generation, and the font style encoding network and the text generation network can be obtained. The system resources are less consumed during the training process, thereby reducing the difficulty and cost of network training.

[0089] Figure 5 FIG. 1 is a schematic diagram of a preset neural network according to an exemplary embodiment. Figure 5 As shown, the preset neural network may include a preset font style encoding network, a preset text generation network and a preset discrimination network, and the preset neural network as a whole is a Generative Adversarial Network (GAN) structure. In addition, the preset neural network uses SpatialAdaIN and AdaIN to input spatial information of sample text content information and sample font style information of different levels into each layer of the generator.

[0090] Next, the process of using the Figure 5 preset neural network to train the font style encoding network and the text generation network will be described:

[0091] Suppose the first sample text is "Gong,..., Men, Zheng" of "Founder Cartoon", which is used to represent the font style information of "Founder Cartoon", and the second sample text is "De" in Song font, which is used to represent the text content of "De". The first sample text is input into the preset style encoding network to obtain the sample font style information. The sample font style information is input into the preset text generation network in the way of AdaIN, and the sample text content information of the second sample text is inserted into the preset text generation network in the form of SpatialAdaIN. The preset text generation network outputs the text "De" under "Founder Cartoon" (i.e., the reference text). The preset discriminator network discriminates the reference text output by this training from the text "De" under "Founder Cartoon" in the sample text set (i.e., the reference text) to obtain the loss information. During the training process, the parameters of the network are continuously adjusted until the loss information meets the preset conditions, and then the training process stops, obtaining the trained font style encoding network and text generation network.

[0092] Figure 6 is a flowchart of a lattice encoding network and a text generation network obtained by training shown according to an exemplary embodiment. As Figure 6 shown, in the above S303, based on the sample font style information of the above first sample text and the sample text content information of the above second sample text, the preset neural network is trained for text generation. During the above text generation training process, the latent space of the above sample font style information is constrained to a normal distribution, and obtaining the font style encoding network and the text generation network may include:

[0093] S3031. Map the above first sample text into the latest normal distribution based on the above preset font style encoding network to obtain the current sample font style information.

[0094] Optionally, in the above step S3031, the preset font style encoding network may be a forward propagation network, that is, the forward propagation network takes the first sample text (i.e., the style reference set R S ) as the input and outputs the current sample font style information (i.e., the style embedding vector ).

[0095] Exemplarily, the style embedding vector Z S can be obtained by random sampling. The forward propagation network can map the style reference set R S into the latest normal distribution and output two vectors and The above two vectors represent the multivariate normal distribution N(μ s ,σ s ) parameter μ s and σ s .

[0096] S3033. Based on the preset font style encoding network, the standard normal distribution and the current sample font style information are processed to obtain the sample font style information.

[0097] In the embodiment of the present application, in the above step S3033, the preset font style encoding network can make the current sample font style information align with the multivariate standard normal distribution, so as to obtain the sample font style information.

[0098] Figure 7 FIG. 1 is a schematic diagram showing a method of obtaining sample font style information according to an exemplary embodiment. Figure 7 As shown, in the above step S3033, the above-mentioned processing of the standard normal distribution and the above-mentioned current sample font style information based on the above-mentioned preset font style encoding network to obtain the above-mentioned sample font style information may include:

[0099] S30331. Based on the preset font style encoding network, randomly obtain a feature vector corresponding to the current sample font style information from the standard normal distribution.

[0100] S30333. Based on the preset font style encoding network, the latest normal distribution is updated through the difference information between the feature vector and the current sample font style information, and the updated latest normal distribution is used as the latest normal distribution.

[0101] S30335. Based on the above-mentioned preset font style encoding network, the above-mentioned first sample text is mapped to the latest normal distribution to obtain the current sample font style information, and the above-mentioned updated latest normal distribution is used as the above-mentioned latest normal distribution again. Repeat until the above-mentioned difference information meets the preset conditions and stops.

[0102] S30337. Based on the preset font style encoding network, the current sample font style information when the difference information meets the preset conditions is used as the sample font style information.

[0103] For example, in the above step S30331, during training, in order to make the current sample font style information (i.e., style embedding vector ) is aligned with the multivariate standard normal distribution, and the preset font style encoding network can randomly determine a feature vector corresponding to the current sample font style information from the standard normal distribution. In the above steps S20333-S20337, the preset encoding network can calculate the difference information between the feature vector and the above current sample font style information, and use the difference information as the distribution loss value. Based on the distribution loss value, the latest normal distribution in the preset font style encoding network can be adjusted and updated, so that the latest normal distribution is continuously adjusted to be able to be used to obtain high-quality sample font style information, that is, the latest normal distribution is continuously adjusted so that the difference information meets the preset conditions, and the current sample font style information when the difference information meets the preset conditions is used as the sample font style information.

[0104] In one approach, the following constraints can be imposed on the preset style encoder:

[0105]

[0106] Among them, N represents the multivariate normal distribution, KL refers to the KL divergence, and the KL divergence is an indicator to measure the degree of matching between two probability distributions. The greater the difference between the two distributions, the greater the KL divergence.

[0107] Accordingly, in the above step S30333, the KL divergence between the feature vector and the above current sample font style information can be calculated, and based on the KL divergence, the latest normal distribution in the preset font style encoding network can be adjusted and updated, so that the latest normal distribution is continuously adjusted to be able to be used to obtain higher-quality sample font style information, that is, the latest normal distribution is continuously adjusted so that the KL divergence is less than the preset divergence threshold, and the current sample font style information when the KL divergence is less than the preset divergence threshold is used as the sample font style information.

[0108] In another way, in the above step S30333, the maximum mean difference algorithm can also be used to calculate the difference information between the feature vector and the above current sample font style information. The maximum mean difference algorithm is used to measure the difference between two distributions.

[0109] In the embodiment of the present application, by applying constraints to the preset font style encoding network, the current sample font style information (style embedding vector Z S ) is sampled from a multivariate standard normal distribution, so the style embedding vector Z S All dimensions of In this space, we can select any style, thereby compressing the style embedding Z SThe space of different styles is shortened, which makes the change of style latent space smoother and avoids the network from encountering discontinuities, thereby improving the training accuracy of the font style encoding network.

[0110] S3035. Based on the preset text generation network, generate the current text corresponding to the sample font style information and the sample text content information.

[0111] In the embodiment of the present application, given sample font style information (style S i ) and sample text content (content C j ), the goal of the preset text generation network is to generate text x with corresponding style and content ij The input of the preset text generation network includes two branches: content branch and style branch. The input of the style branch is the sample font style information obtained by the preset font style encoding network (i.e., style embedding ), and the content branch inputs the content text image, so the current text generated by the preset text generation network

[0112] S3037. Based on the preset discriminant network, the current text, reference text, sample font style information and sample text content information are discriminated and processed to obtain loss information.

[0113] S3039. Based on the above loss information, the above preset font style encoding network and the above preset text generation network are trained to obtain the above font style encoding network and the above text generation network; the above reference text represents the text of the above sample text content information under the above sample font style information.

[0114] The preset discriminant network is an important part of GAN. Its goal is to determine whether the given current text is realistic enough. If it is realistic, the preset discriminant network will give the current text a high score, otherwise it will give a low score. During training, the preset discriminant network usually believes that the current text generated by the preset text generation network is not realistic enough, and only the reference fonts in the sample text set are realistic. In this way, in order to deceive the preset discriminant network, the preset text generation network can only generate more realistic images. The preset text generation network and the preset discriminant network continue to improve their capabilities in such a zero-sum game. In the end, the current text generated by the preset text generation network is close to the reference text, so that a high-quality text generation network can be trained.

[0115] The purpose of the preset text generation network is to deceive the preset discriminant network, that is, the preset text generation network has no direct supervisory information, but relies on the preset discriminant network to provide supervisory information. In an optional embodiment, the preset discriminant network can use two preset discriminant networks D1 and D2 with the same structure to discriminate images of different sizes. Small-sized images can make the preset discriminant network have a larger receptive field, while large-sized images make the preset discriminant network pay more attention to details, and can also avoid the problem of overfitting to a certain extent.

[0116] In a specific embodiment, for each discriminative network, a hinge loss function can be used as the loss function of GAN:

[0117]

[0118] Among them, G, D, and E refer to the preset text generation network, the preset discriminant network, and the preset font style encoding network, respectively, and k refers to the number of preset discriminant networks.

[0119] In an exemplary embodiment, in order to enable the preset discriminant network to distinguish the content and style of the font and improve the network quality, in S3037, in addition to the current text and the reference text, the input of the preset discriminant network may also include sample font style information and sample text content information.

[0120] In another exemplary embodiment, in order to stabilize the training process, feature matching loss can also be used to align the features of the current text and the reference text in each layer of the preset discriminant network. Represents the input text x in the kth discriminator, the feature of the i-th layer, then the feature matching loss can be expressed as:

[0121]

[0122] in, T represents the number of convolutional layers of the preset discriminant network, N t Indicates the number of elements in the t-th layer feature of the preset discriminant network.

[0123] In summary, after constructing each part of the preset neural network, the overall optimization goal of the entire preset neural network is:

[0124]

[0125] Among them, the hyperparameter λ FM =10,λ VAE=0.05, G, D, and E refer to the preset text generation network, the preset discrimination network, and the preset font style encoding network, respectively.

[0126] The preset neural network of the embodiment of the present application may include a preset font style encoding network, a preset text generation network and a preset discriminant network. The preset font style encoding network constrains the latent space of sample font style information to be normally distributed, thereby compressing the font style information, shortening the distance between different font style information, making the change of the style latent space smoother, and avoiding the network from encountering discontinuities, thereby improving the training accuracy of the font style encoding network and the text generation network, and reducing the training cost and difficulty; in addition, through the preset text generation network, the current text corresponding to the sample font style information and the sample text content information is generated, and through the preset discriminant network, the current text, reference text, sample font style information and sample text content information are discriminated and processed to obtain loss information, and based on the loss information, the font style encoding network and the text generation network are trained, which further improves the training accuracy of the font style encoding network and the text generation network and reduces the training cost.

[0127] Figure 8 FIG. 1 is a schematic diagram showing a method of standardizing sample font style information and sample text content information according to an exemplary embodiment. Figure 8 As shown, in an optional embodiment, the above method may further include:

[0128] S401. Decouple the above sample font style information.

[0129] S403. Standardize the decoupled sample font style information to obtain standard sample font style information.

[0130] S405. Standardize the above sample text content information to obtain standard sample text content information.

[0131] Accordingly, in the above step S3035, the above-mentioned current text corresponding to the above-mentioned sample font style information and the above-mentioned sample text content information is generated based on the above-mentioned preset text generation network, including:

[0132] Based on the preset text generation network, the current text corresponding to the standard sample text content information and the standard sample font style information is generated.

[0133] In an alternative embodiment, continue as Figure 5 As shown, the structure of the preset text generation network can be a SPADE+AdaIN structure. Among them, SPADE is a generation model that converts a segmentation map into a real scene map. As a backbone network, it can better retain the structural information of the text.

[0134] Exemplarily, in the above steps S401-S403, the sample font style information can be input into ML for decoupling, and the decoupled sample font style information can be standardized by AdaIN to obtain the standard sample font style information after standardization, and the decoupled style can be input into each layer of the network by AdaIN, and the style of the generated image can be controlled by controlling the feature statistical information. The font style information is decoupled after multiple layers of fully connected layers, and then sent to each layer of the network. In this way, the preset text generation network can extract font style information from multiple semantic levels. In addition, SPADE uses AdaIN as a standardization method, which can well preserve the spatial information of the original segmentation. That is, through the structure of the SPADE+AdaIN generator, the quality of font fusion can be improved.

[0135] In the process of text generation, the content branch retains the stroke structure of the text. The stroke structure of the text (i.e., the text content information) is a key factor. Exemplarily, in the above step S405, the sample text content information can be inserted into the network in the form of SpatialAdaIN to standardize the sample text content information and obtain the standard sample text content information, thereby retaining the stroke structure of the text (i.e., the original segmented spatial information) and improving the generation quality of the current text.

[0136] In a specific embodiment, the specific process of performing the standardization process by means of AdaIN may be as follows:

[0137] AdaIN receives a content input x and a style input s, and normalizes x by aligning the channel-level (C) mean and standard deviation of x to s. AdaIN does not require learned affine parameters, and can adaptively calculate affine parameters from the style input, as follows:

[0138] AdaIN(x,s)=σ(s)(σ(x)x-μ(x))+μ(s),

[0139] The IN in AdaIN means that for each feature channel (C) of each sample (N), the mean and standard deviation are calculated in the space (H, W).

[0140] In a specific embodiment, the specific process of performing the standardization process by means of Spatial AdaIN may be as follows:

[0141] SpatialAdaIN is similar to AdaIN in that there are no radiation parameters to be learned and it is an adaptive normalization method. In particular, the mean and standard deviation of SpatialAdaIN statistics are at the pixel level, not the channel level. Pixel-level statistics can increase the complexity of the model and better preserve the spatial information of the image, thereby better maintaining the stroke structure of the text.

[0142] In a feasible embodiment, low-resolution sample text content information can also be used as input to a preset text generation network. Starting from low-resolution text, the preset text generation network only needs to slightly adjust the position, thickness and other details of each stroke according to the style to generate text of the corresponding style, which greatly reduces the difficulty of text generation.

[0143] In a feasible embodiment, the embodiment of the present application also provides a font quality detection model and a font similarity detection model to measure the font quality and innovation level of the generated target text.

[0144] Exemplarily, the font quality detection model is mainly used to evaluate whether the font is complete, whether it is difficult to recognize, etc. The font quality detection model can be a two-class text quality evaluation model. The positive samples of the data set are high-quality text and real text generated by the model, and the negative samples are low-quality text generated by the model. The test shows that the classification accuracy of the model is 93%, and it has a strong quality resolution ability. Furthermore, in order to avoid the generated text being too similar to the training text, a font similarity detection model can also be trained to evaluate the similarity between the font of the generated text and the font of the training text. The evaluation index can be cosine similarity.

[0145] In a specific embodiment, a preset number of font styles, each of which contains a preset number of commonly used characters (contents), may be selected as a sample text set, and the sample text set may be trained according to the above training process. Fig. 9 FIG. 1 is a schematic diagram showing a target text generated by the text generation method of an embodiment of the present application according to an exemplary embodiment. Fig. 9 As shown, the font style encoding network and the text generation network provided in the embodiment of the present application can generate texts of different styles, including square and straight texts, texts with abstract strokes and artistic effects, and texts with different thicknesses, and the same text can maintain its own style. Under the premise of ensuring the diversity of styles, the generated text has good integrity and high quality, and basically no problems of missing and merging strokes will occur.

[0146] In a feasible embodiment, an Empirical Mode Decomposition (EMD) model can also be trained, and text can be generated through this EMD. Table 1 is a comparison table of the fusion effects between the text generated by EMD and the target text generated by the method in the embodiment of the present application. Fig.10 It is a comparison diagram of the fusion effect shown according to an exemplary embodiment.

[0147] As shown in Table 1, the fusion effect of the target text generated by the method in the embodiment of the present application is better. Among them, FID is the abbreviation of Frechet Inception Distance score, and its Chinese name is distance score. The yield rate refers to the ratio between the text with better generated quality and the total generated text.

[0148] Table 1 Comparison of fusion effects

[0149] Model FID↓ Yield↑ EMD 32.66 63.30% This application 28.10 91.49%

[0150] As Fig.10 shown, the text fused by EMD is prone to problems such as missing strokes and merged strokes, resulting in incomplete fonts. For example, the character "真" in the first row is missing a horizontal stroke, and the characters "练" and "解" have merged strokes, resulting in misspelled characters. However, for the target subgraph generated by the embodiment of the present application, there are few problems of missing and merged strokes, which can well retain the structure of the text, rarely have misspelled characters, and greatly improve the quality of the font.

[0151] Fig.11 It is a schematic diagram of similar fonts obtained by detecting the font of the target text through a font similarity detection model shown according to an exemplary embodiment. As Fig.11 shown, it can be seen from the first three rows that the font of the generated target text has an obvious style difference from the fonts of the texts in the training set (i.e., Fig.11 the most similar font and the second most similar font in it). However, the font of the text shown in the fourth row is highly similar to the font of the text in the font library, and this text can be automatically filtered out to screen out inappropriate text, further improving the quality of the generated target text.

[0152] In a feasible embodiment, such as the text generation method and the network training method for text generation disclosed in the present application, font style information, text content information, etc. can be stored on the blockchain.

[0153] Fig.12 It is a text generation device shown according to an exemplary embodiment. As Fig.12 shown, this device can at least include:

[0154] The text acquisition module 501 may be used to acquire at least two candidate texts with different font style information from the text set to be processed.

[0155] The font style information generating module 503 may be used to generate font style information corresponding to the at least two candidate characters based on a font style encoding network.

[0156] The target text generation module 505 can be used to generate target text corresponding to the above-mentioned font style information and text content information based on the text generation network; the above-mentioned text content information represents the content of the text in the above-mentioned text set to be processed.

[0157] The above-mentioned font style encoding network and text generation network are obtained by training a preset neural network for text generation, and the latent space of sample font style information used in the text generation training process is constrained to be normally distributed.

[0158] In an exemplary embodiment, the font style information generating module 503 may be used to map the at least two candidate characters to the normal distribution based on the font style encoding network to obtain font style information corresponding to each of the at least two candidate characters.

[0159] In an exemplary embodiment, the above device may further include:

[0160] The target font style information determination module can be used to calculate the average value of the above font style information based on the above font style encoding network to obtain the target font style information.

[0161] Correspondingly, the target text generation module 505 can be used to generate the target text corresponding to the target font style information and the text content information based on the text generation network.

[0162] In an exemplary embodiment, the above device may further include:

[0163] The first decoupling module can be used to decouple the above font style information.

[0164] The first standardization processing module can be used to perform standardization processing on the decoupled font style information to obtain standard font style information.

[0165] The second standardization processing module can be used to perform standardization processing on the above text content information to obtain standard text content information.

[0166] Correspondingly, the target text generation module 505 can be used to generate the target text corresponding to the standard font style information and the standard text content information based on the text generation network.

[0167] Fig.13 A network training device for text generation is shown according to an exemplary embodiment. Fig.13 As shown, the device may also include:

[0168] The sample text acquisition module 601 is used to extract a first sample text and a second sample text from a sample text set.

[0169] The training module 603 is used to perform text generation training on a preset neural network based on the sample font style information of the first sample text and the sample text content information of the second sample text. During the text generation training process, the latent space of the sample font style information is constrained to be normally distributed to obtain a font style encoding network and a text generation network.

[0170] In an exemplary embodiment, the preset neural network includes a preset font style encoding network, a preset text generation network and a preset discrimination network, and the training module 603 may include:

[0171] The mapping unit can be used to map the first sample text into the latest normal distribution based on the preset font style encoding network to obtain the current sample font style information.

[0172] The sample font style information generating unit may be used to process the standard normal distribution and the current sample font style information based on the preset font style encoding network to obtain the sample font style information.

[0173] The current text generation unit can be used to generate the current text corresponding to the sample font style information and the sample text content information based on the preset text generation network.

[0174] The loss information determination unit can be used to perform discrimination processing on the above-mentioned current text, reference text, the above-mentioned sample font style information and the above-mentioned sample text content information based on the above-mentioned preset discrimination network to obtain loss information.

[0175] The network generation unit can be used to train the preset font style encoding network and the preset text generation network based on the loss information to obtain the font style encoding network and the text generation network; the reference text represents the text of the sample text content information under the sample font style information.

[0176] In an exemplary implementation, the sample font style information generating unit may include:

[0177] The feature vector acquisition subunit may be used to randomly acquire a feature vector corresponding to the current sample font style information from the standard normal distribution based on the preset font style encoding network.

[0178] The updating subunit can be used to determine the difference information between the above-mentioned feature vector and the above-mentioned current sample font style information based on the above-mentioned preset font style encoding network, update the above-mentioned latest normal distribution based on the above-mentioned difference information, and use the updated latest normal distribution as the above-mentioned latest normal distribution.

[0179] The repeating subunit can be used to map the first sample text to the latest normal distribution based on the preset font style encoding network to obtain the current sample font style information, and repeat between the updated latest normal distribution as the latest normal distribution, until the difference information meets the preset conditions.

[0180] The sample font style information determination subunit may be configured to use the current sample font style information when the difference information meets a preset condition as the sample font style information based on the preset font style encoding network.

[0181] In an exemplary embodiment, the above device may further include:

[0182] The second decoupling module can be used to decouple the above sample font style information.

[0183] The third standardization processing module can be used to perform standardization processing on the decoupled sample font style information to obtain standard sample font style information.

[0184] The fourth standardization processing module can be used to perform standardization processing on the above sample text content information to obtain standard sample text content information.

[0185] Correspondingly, the above-mentioned current text generation unit can be used to generate the above-mentioned current text corresponding to the above-mentioned standard sample text content information and the above-mentioned standard sample font style information based on the above-mentioned preset text generation network.

[0186] It should be noted that the device embodiment provided in the embodiments of the present application and the above-mentioned method embodiment are based on the same inventive concept.

[0187] An embodiment of the present application also provides an electronic device, which includes a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or at least one program is loaded and executed by the processor to implement a text generation method or a network training method for text generation provided in any of the above embodiments.

[0188] An embodiment of the present application also provides a computer-readable storage medium, which can be set in a terminal to store at least one instruction or at least one program related to a text generation method or a network training method for text generation in a method embodiment, and the at least one instruction or at least one program is loaded and executed by a processor to implement the text generation method or the network training method for text generation provided in the above method embodiment.

[0189] Optionally, in the embodiment of this specification, the storage medium may be located in at least one of the multiple network servers of the computer network. Optionally, in this embodiment, the above storage medium may include but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store program codes.

[0190] The memory of the embodiment of this specification can be used to store software programs and modules, and the processor executes various functional applications and data processing by running the software programs and modules stored in the memory. The memory may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, applications required for functions, etc.; the data storage area may store data created according to the use of the device, etc. In addition, the memory may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage device. Accordingly, the memory may also include a memory controller to provide the processor with access to the memory.

[0191] The embodiment of the present application also provides a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. The processor of the computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the text generation method or the network training method for text generation provided in the above method embodiment.

[0192] The text generation method or text generation network training method provided in the embodiments of the present application can be executed in a terminal, a computer terminal, a server or a similar computing device. Taking running on a server as an example, Fig.14 1 is a hardware structure block diagram of a server for text generation or network training of text generation provided by an embodiment of the present application. Fig.14As shown, the server 700 may have relatively large differences due to different configurations or performances, and may include one or more central processing units (CPU) 710 (the central processing unit 710 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 730 for storing data, and one or more storage media 720 (such as one or more mass storage devices) for storing application programs 723 or data 722. Among them, the memory 730 and the storage medium 720 can be short-term storage or permanent storage. The program stored in the storage medium 720 may include one or more modules, each of which may include a series of instruction operations on the server. Furthermore, the central processing unit 710 can be configured to communicate with the storage medium 720 and execute a series of instruction operations in the storage medium 720 on the server 700. The server 700 may also include one or more power supplies 760, one or more wired or wireless network interfaces 750, one or more input and output interfaces 740, and / or one or more operating systems 721, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, etc.

[0193] The input / output interface 740 may be used to receive or send data via a network. The specific example of the network may include a wireless network provided by a communication provider of the server 700. In one example, the input / output interface 740 includes a network adapter (Network Interface Controller, NIC), which may be connected to other network devices via a base station so as to communicate with the Internet. In one example, the input / output interface 740 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0194] It can be understood by those skilled in the art that Fig.14 The structure shown is only for illustration and does not limit the structure of the above electronic device. Fig.14 More or fewer components as shown, or with Fig.14 Different configurations shown.

[0195] It should be noted that the above-mentioned sequence of the embodiments of the present application is for description only and does not represent the advantages and disadvantages of the embodiments. The above-mentioned specific embodiments of this specification are described. Other embodiments are within the scope of the attached claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0196] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device and server embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.

[0197] A person skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware, or by a program to instruct the relevant hardware, and the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.

[0198] The above are only preferred embodiments of the present application and are not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the protection scope of the present application.

Claims

1. A method for generating text, characterized in that: The method comprises: Obtain at least two candidate characters with different font style information from the character set to be processed; Generate font style information corresponding to each of the at least two candidate characters based on a font style encoding network; Based on the text generation network, generating target text corresponding to the font style information and text content information; the text content information represents the content of the text in the to-be-processed text set; Among them, the font style encoding network and the text generation network are obtained by training a preset neural network for text generation. The preset neural network includes a preset font style encoding network, a preset text generation network and a preset discriminant network. The preset font style encoding network is used to map the first sample text in the sample text set to the latest normal distribution to obtain the current sample font style information, and is used to process the standard normal distribution and the current sample font style information to obtain the sample font style information of the first sample text; the current sample font style information is sampled from the standard normal distribution, and each dimension of the current sample font style information is near the mean of 0; the preset text generation network is used to generate the current text corresponding to the sample font style information and the sample text content information of the second sample text in the sample text set; the preset discriminant network is used to discriminate the current text, the reference text, the sample font style information and the sample text content information to obtain loss information; the loss information is used to train the preset font style encoding network and the preset text generation network to obtain the font style encoding network and the text generation network; the reference text represents the text of the sample text content information under the sample font style information.

2. The method according to claim 1, characterized in that The generating of the font style information corresponding to the at least two candidate characters based on the font style encoding network includes: Based on the font style encoding network, the at least two candidate characters are mapped to the normal distribution to obtain font style information corresponding to each of the at least two candidate characters.

3. The method according to claim 1, characterized in that The method further comprises: Based on the font style encoding network, calculating the average value of the font style information to obtain target font style information; The generating target text corresponding to the font style information and text content information based on the text generation network includes: Based on the text generation network, the target text corresponding to the target font style information and the text content information is generated.

4. The method according to any one of claims 1 to 3, characterized in that The method further comprises: Decoupling the font style information; Standardize the decoupled font style information to obtain standard font style information; Performing standardization processing on the text content information to obtain standard text content information; Accordingly, the generating target text corresponding to the font style information and text content information based on the text generation network includes: Based on the text generation network, the target text corresponding to the standard font style information and the standard text content information is generated.

5. A network training method for text generation, characterized in that: The method comprises: Extracting a first sample text and a second sample text from the sample text set; Mapping the first sample text to the latest normal distribution based on a preset font style encoding network in a preset neural network to obtain current sample font style information; Based on the preset font style encoding network, the standard normal distribution and the current sample font style information are processed to obtain sample font style information; the current sample font style information is sampled from the standard normal distribution, and each dimension of the current sample font style information is near a mean of 0; Based on a preset text generation network in the preset neural network, a current text corresponding to the sample font style information and the sample text content information of the second sample text is generated; based on a preset discrimination network in the preset neural network, the current text, the reference text, the sample font style information and the sample text content information are discriminated and processed to obtain loss information; The preset font style encoding network and the preset text generation network are trained based on the loss information to obtain the font style encoding network and the text generation network; the reference text represents the text of the sample text content information under the sample font style information.

6. The method according to claim 5, characterized in that The step of processing the standard normal distribution and the current sample font style information based on the preset font style encoding network to obtain the sample font style information includes: Based on the preset font style encoding network, randomly acquiring a feature vector corresponding to the current sample font style information from the standard normal distribution; Based on the preset font style encoding network, determining difference information between the feature vector and the current sample font style information, updating the latest normal distribution based on the difference information, and re-using the updated latest normal distribution as the latest normal distribution; Based on the preset font style encoding network, mapping the first sample text into the latest normal distribution to obtain current sample font style information and using the updated latest normal distribution as the latest normal distribution are repeated until the difference information meets a preset condition; Based on the preset font style encoding network, the current sample font style information when the difference information meets the preset condition is used as the sample font style information.

7. The method according to claim 5, characterized in that The method further comprises: Decoupling the sample font style information; Standardizing the decoupled sample font style information to obtain standard sample font style information; Standardizing the sample text content information to obtain standard sample text content information; Correspondingly, the generating of the current text corresponding to the sample font style information and the sample text content information of the second sample text based on the preset text generation network in the preset neural network includes: Based on the preset text generation network, the current text corresponding to the standard sample text content information and the standard sample font style information is generated.

8. A text generation device, characterized in that: The device comprises: A text acquisition module, used for acquiring at least two candidate texts with different font style information from the text set to be processed; A font style information generating module, used for generating font style information corresponding to the at least two candidate characters respectively based on a font style encoding network; A target text generation module, for generating target text corresponding to the font style information and text content information based on a text generation network; the text content information represents the content of the text in the to-be-processed text set; Among them, the font style encoding network and the text generation network are obtained by training a preset neural network for text generation. The preset neural network includes a preset font style encoding network, a preset text generation network and a preset discriminant network. The preset font style encoding network is used to map the first sample text in the sample text set to the latest normal distribution to obtain the current sample font style information, and is used to process the standard normal distribution and the current sample font style information to obtain the sample font style information of the first sample text; the current sample font style information is sampled from the standard normal distribution, and each dimension of the current sample font style information is near the mean of 0; the preset text generation network is used to generate the current text corresponding to the sample font style information and the sample text content information of the second sample text in the sample text set; the preset discriminant network is used to discriminate the current text, the reference text, the sample font style information and the sample text content information to obtain loss information; the loss information is used to train the preset font style encoding network and the preset text generation network to obtain the font style encoding network and the text generation network; the reference text represents the text of the sample text content information under the sample font style information.

9. The device according to claim 8, characterized in that The font style information generating module is used to map the at least two candidate characters to the normal distribution based on the font style encoding network to obtain the font style information corresponding to each of the at least two candidate characters.

10. The device according to claim 8, characterized in that The device also includes: The target font style information determination module is used to calculate the average value of the font style information based on the font style encoding network to obtain the target font style information: The target text generation module is used to generate the target text corresponding to the target font style information and the text content information based on the text generation network.

11. The device according to any one of claims 8 to 10, characterized in that The device also includes: A first decoupling module, used for decoupling the font style information; A first standardization processing module, used for standardizing the decoupled font style information to obtain standard font style information; A second standardization processing module is used to perform standardization processing on the text content information to obtain standard text content information; The target text generation module is used to generate the target text corresponding to the standard font style information and the standard text content information based on the text generation network.

12. A network training device for text generation, characterized in that: The device comprises: A sample text acquisition module, used to extract a first sample text and a second sample text from a sample text set; A training module, configured to perform text generation training on a preset neural network based on the sample font style information of the first sample text and the sample text content information of the second sample text, wherein during the text generation training, the latent space of the sample font style information is constrained to be a normal distribution to obtain a font style encoding network and a text generation network; The training module includes: A mapping unit, used to map the first sample text to the latest normal distribution based on a preset font style encoding network in a preset neural network to obtain current sample font style information; A sample font style information generating unit, configured to process the standard normal distribution and the current sample font style information based on the preset font style encoding network to obtain sample font style information; the current sample font style information is sampled from the standard normal distribution, and each dimension of the current sample font style information is near a mean of 0; A current text generation unit, configured to generate a current text corresponding to the sample font style information and the sample text content information based on a preset text generation network in the preset neural network; A loss information determination unit, configured to perform a discrimination process on the current text, the reference text, the sample font style information and the sample text content information based on a preset discrimination network in the preset neural network to obtain loss information; A network generation unit is used to train the preset font style encoding network and the preset text generation network based on the loss information to obtain the font style encoding network and the text generation network; the reference text represents the text of the sample text content information under the sample font style information.

13. The device according to claim 12, characterized in that The sample font style information generating unit comprises: A feature vector acquisition subunit, configured to randomly acquire a feature vector corresponding to the current sample font style information from the standard normal distribution based on the preset font style encoding network; An updating subunit, configured to determine difference information between the feature vector and the current sample font style information based on the preset font style encoding network, update the latest normal distribution based on the difference information, and use the updated latest normal distribution as the latest normal distribution; a repeating subunit, configured to repeat, based on the preset font style encoding network, the steps of mapping the first sample text into the latest normal distribution to obtain the current sample font style information, and reusing the updated latest normal distribution as the latest normal distribution, until the difference information satisfies a preset condition; The sample font style information determination subunit is used to use the current sample font style information when the difference information meets a preset condition as the sample font style information based on the preset font style encoding network.

14. The device according to claim 12, characterized in that The device also includes: A second decoupling module, used for decoupling the sample font style information; A third standardization processing module is used to perform standardization processing on the decoupled sample font style information to obtain standard sample font style information; A fourth standardization processing module, used for performing standardization processing on the sample text content information to obtain standard sample text content information; Correspondingly, the current text generation unit is used to generate the current text corresponding to the standard sample text content information and the standard sample font style information based on the preset text generation network.

15. An electronic device, characterized in that: The electronic device includes a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or at least one program is loaded and executed by the processor to implement the text generation method as described in any one of claims 1 to 4 or the network training method for text generation as described in any one of claims 5 to 7.

16. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores at least one instruction or at least one program, and the at least one instruction or the at least one program is loaded and executed by the processor to implement the text generation method according to any one of claims 1 to 4 or the network training method for text generation according to any one of claims 5 to 7.

17. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, it implements the text generation method described in any one of claims 1 to 4 or the network training method for text generation described in any one of claims 5 to 7.

Citation Information

Patent Citations

  • Model training method and device, font library establishing method and device, equipment and storage medium

    CN113792855A