CN111898338A - Text generation method and device and electronic equipment - Google Patents

Text generation method and device and electronic equipment Download PDF

Info

Publication number
CN111898338A
CN111898338A CN202010677523.5A CN202010677523A CN111898338A CN 111898338 A CN111898338 A CN 111898338A CN 202010677523 A CN202010677523 A CN 202010677523A CN 111898338 A CN111898338 A CN 111898338A
Authority
CN
China
Prior art keywords
text
feature vector
input image
generation method
joint
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202010677523.5A
Other languages
Chinese (zh)
Other versions
CN111898338B (en
Inventor
陈家泽
李磊
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing ByteDance Network Technology Co Ltd
Original Assignee
Beijing ByteDance Network Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing ByteDance Network Technology Co Ltd filed Critical Beijing ByteDance Network Technology Co Ltd
Priority to CN202010677523.5A priority Critical patent/CN111898338B/en
Priority claimed from CN202010677523.5A external-priority patent/CN111898338B/en
Publication of CN111898338A publication Critical patent/CN111898338A/en
Application granted granted Critical
Publication of CN111898338B publication Critical patent/CN111898338B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/12Use of codes for handling textual entities
    • G06F40/126Character encoding
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/30Information retrieval; Database structures therefor; File system structures therefor of unstructured textual data
    • G06F16/35Clustering; Classification
    • G06F16/355Class or cluster creation or modification
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F18/00Pattern recognition
    • G06F18/20Analysing
    • G06F18/22Matching criteria, e.g. proximity measures
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/279Recognition of textual entities
    • G06F40/289Phrasal analysis, e.g. finite state techniques or chunking
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/30Semantic analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/045Combinations of networks
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V10/00Arrangements for image or video recognition or understanding
    • G06V10/40Extraction of image or video features

Abstract

The embodiment of the disclosure discloses a text generation method and device, electronic equipment and a computer-readable storage medium. The text generation method comprises the following steps: acquiring an input image and a first text; extracting the features of the input image to obtain a feature vector of the input image; coding the first text to obtain a feature vector of the first text; obtaining a combined feature vector according to the feature vector of the input image and the feature vector of the first text; and decoding the joint feature vector to generate a second text. The method generates the combined feature vector through the image features and the text features, and generates the second text describing the image through decoding the training special vector, thereby solving the technical problems of time consumption and low efficiency in generating the image description information in the prior art.

Description

Text generation method and device and electronic equipment
Technical Field
The present disclosure relates to the field of text generation, and in particular, to a text generation method and apparatus, an electronic device, and a computer-readable storage medium.
Background
The automatic generation of the text is an important research direction in the field of natural language processing, and the realization of automatic generation of the text is also an important mark for artificial intelligence to mature. It is expected that a day in the future, computers will be able to write as human beings do, and will be able to write high quality natural language text. The automatic text generation technology has a wide application prospect.
On the display pages of many websites, pictures and description information of articles are generally displayed. It is often necessary for a user to write a piece of information describing an item in a picture after uploading the picture so as to arouse the interest of other users and click on a link corresponding to the picture. Then, because the number of pictures is generally large, it is time-consuming and inefficient to write a piece of textual information for each picture to describe the items in the picture.
Disclosure of Invention
This summary is provided to introduce a selection of concepts in a simplified form that are further described below in the detailed description. This summary is not intended to identify key features or essential features of the claimed subject matter, nor is it intended to be used to limit the scope of the claimed subject matter.
In order to solve the problem that generating a text in the prior art is time-consuming and inefficient, the embodiments of the present disclosure propose the following technical solutions.
In a first aspect, an embodiment of the present disclosure provides a text generation method, including:
acquiring an input image and a first text;
extracting the features of the input image to obtain a feature vector of the input image;
coding the first text to obtain a feature vector of the first text;
obtaining a combined feature vector according to the feature vector of the input image and the feature vector of the first text;
and decoding the joint feature vector to generate a second text.
In a second aspect, an embodiment of the present disclosure provides a text generation apparatus, including:
the input module is used for acquiring an input image and a first text;
the extraction module is used for extracting the features of the input image to obtain a feature vector of the input image;
the encoding module is used for encoding the first text to obtain a feature vector of the first text;
the combination module is used for obtaining a combination feature vector according to the feature vector of the input image and the feature vector of the first text;
and the decoding module is used for decoding the joint feature vector to generate a second text.
In a third aspect, an embodiment of the present disclosure provides an electronic device, including: at least one processor; and the number of the first and second groups,
a memory communicatively coupled to the at least one processor; wherein the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method of any one of the preceding first aspects.
In a fourth aspect, the present disclosure provides a non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium stores computer instructions for causing a computer to perform the method of any one of the foregoing first aspects.
The embodiment of the disclosure discloses a text generation method and device, electronic equipment and a computer-readable storage medium. The text generation method comprises the following steps: acquiring an input image and a first text; extracting the features of the input image to obtain a feature vector of the input image; coding the first text to obtain a feature vector of the first text; obtaining a combined feature vector according to the feature vector of the input image and the feature vector of the first text; and decoding the joint feature vector to generate a second text. The method generates the combined feature vector through the image features and the text features, and generates the second text describing the image through decoding the training special vector, thereby solving the technical problems of time consumption and low efficiency in generating the image description information in the prior art.
The foregoing is a summary of the present disclosure, and for the purposes of promoting a clear understanding of the technical means of the present disclosure, the present disclosure may be embodied in other specific forms without departing from the spirit or essential attributes thereof.
Drawings
The above and other features, advantages and aspects of various embodiments of the present disclosure will become more apparent by referring to the following detailed description when taken in conjunction with the accompanying drawings. Throughout the drawings, the same or similar reference numbers refer to the same or similar elements. It should be understood that the drawings are schematic and that elements and features are not necessarily drawn to scale.
Fig. 1 is a schematic flowchart of a text generation method according to an embodiment of the present disclosure;
fig. 2 is a schematic flow chart illustrating obtaining a feature vector of a first text in a text generation method according to an embodiment of the present disclosure;
fig. 3 is a schematic flowchart of obtaining a key-value pair of a first text in a text generation method provided in the embodiment of the present disclosure;
fig. 4 is another schematic flow chart of obtaining a feature vector of a first text in the text generation method according to the embodiment of the present disclosure;
fig. 5 is a schematic flow chart of obtaining a joint feature vector in the text generation method provided in the embodiment of the present disclosure;
fig. 6 is a schematic structural diagram of an embodiment of a text generation apparatus provided in an embodiment of the present disclosure;
fig. 7 is a schematic structural diagram of an electronic device provided according to an embodiment of the present disclosure.
Detailed Description
Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While certain embodiments of the present disclosure are shown in the drawings, it is to be understood that the present disclosure may be embodied in various forms and should not be construed as limited to the embodiments set forth herein, but rather are provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the disclosure are for illustration purposes only and are not intended to limit the scope of the disclosure.
It should be understood that the various steps recited in the method embodiments of the present disclosure may be performed in a different order, and/or performed in parallel. Moreover, method embodiments may include additional steps and/or omit performing the illustrated steps. The scope of the present disclosure is not limited in this respect.
The term "include" and variations thereof as used herein are open-ended, i.e., "including but not limited to". The term "based on" is "based, at least in part, on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". Relevant definitions for other terms will be given in the following description.
It should be noted that the terms "first", "second", and the like in the present disclosure are only used for distinguishing different devices, modules or units, and are not used for limiting the order or interdependence relationship of the functions performed by the devices, modules or units.
It is noted that references to "a", "an", and "the" modifications in this disclosure are intended to be illustrative rather than limiting, and that those skilled in the art will recognize that "one or more" may be used unless the context clearly dictates otherwise.
The names of messages or information exchanged between devices in the embodiments of the present disclosure are for illustrative purposes only, and are not intended to limit the scope of the messages or information.
Fig. 1 is a flowchart of an embodiment of a text generation method provided in an embodiment of the present disclosure, where the text generation method provided in this embodiment may be executed by a text generation apparatus, and the text generation apparatus may be implemented as software, or implemented as a combination of software and hardware, and the text generation apparatus may be integrated in some device in a text generation system, such as a text generation server or a text generation terminal device. As shown in fig. 1, the method comprises the steps of:
step S101, acquiring an input image and a first text;
the input image is any image, and illustratively, the image is a display picture of a commodity, and the display picture can be used for displaying the commodity in an e-commerce website or displaying the commodity in an advertisement landing page. The first text is a text input by the user to describe the image, exemplarily, a white woman's shoe in the picture, and then the first text is: white women's shoes.
The input image can also be a key frame in a video, and at this time, acquiring the input image requires acquiring the input video firstly and then extracting the key frame of the input video to obtain the input image; or processing the extracted key frames to obtain a frame image capable of representing the key frames as an input image; the input image may also be a plurality of video frames of the video, without limitation.
Step S102, extracting the characteristics of the input image to obtain a characteristic vector of the input image;
illustratively, the step S102 includes: and inputting the input image into a convolutional neural network to obtain a feature vector of the input image.
In one embodiment, the convolutional neural network is a pre-trained convolutional neural network, for example, the convolutional neural network can classify the articles in the input image through pre-training; if the text generation method is applied to the generation of description texts of clothing pictures, the convolutional neural network can be trained in advance through a clothing training set, so that the convolutional neural network can extract feature vectors representing clothing from the input image.
Illustratively, the convolutional neural network generates a vector with a size of V through convolution calculation of a plurality of convolutional layers on the input image, wherein V represents the number of elements in the vector, and V is an integer greater than 0; illustratively, the vector of size V is a one-dimensional vector comprising V elements. Illustratively, if the vector of size V is a vector of a x b, where a x b V, it may be expanded to a one-dimensional vector of 1 x V, where a and b are both integers greater than 0.
It should be understood that the above extraction method of the feature vector of the input image is only an example, and does not limit the disclosure, and practically any extraction method of the image feature may be applied to the disclosure.
Step S103, coding the first text to obtain a feature vector of the first text;
illustratively, the step S103 includes: and inputting the first text into an encoder for encoding to obtain a feature vector of the first text. Illustratively, the encoder is an LSTM encoder or any other encoder that generates a model of text.
In one embodiment, using the encoder comprises m encoding layers, where m is the number of words in the first text, where m is an integer greater than 0; at the t-th moment, the t-th coding layer of the encoder receives the t-th characters and the vectors input by the t-1-th coding layer to generate the vectors of the t-th layer, wherein t is an integer which is greater than 0 and smaller than m. In one embodiment, a vector output by the m-th layer coding layer is directly used as a feature vector of the first text, the feature vector of the first text comprises information of each word in the first text, and the information of each word is equally weighted in the feature vector of the first text.
Optionally, the step S103 includes:
step S201, extracting texts of the first text to obtain a key value pair of the first text;
step S202, encoding the key value pair to obtain a feature vector of the first text.
In step S201, text extraction is performed on the first text to extract words or words in which key information in the first text can be expressed, so as to generate key-value pairs of the first text.
Exemplarily, the step S201 includes:
step S301, performing word segmentation on the first text to obtain a word segmentation result;
step S302, performing semantic analysis on the word segmentation result to obtain a word segmentation result corresponding to a preset key so as to generate the key value pair.
In step S301, a word segmentation is performed on the first text to obtain at least one word segmentation result. As in the example above, "white women's shoes", the word segmentation was performed to obtain the word segmentation result: "white", "women" and "shoes". In step S302. Performing semantic analysis on the word segmentation result, wherein the semantic analysis can be performed through a semantic model, for example, a semantic module can classify the input characters or words to classify the input characters or words into categories corresponding to preset keys; illustratively, the keys in the key-value pair are: color, gender, class, then the first text "white women's shoes" obtains the key-value pair that corresponds with it through the extraction: color: white, sex: woman, type: a shoe.
Thereafter, in step S202, the key-value pairs are encoded to obtain a feature vector of the first text. The encoding in step S202 may also be performed by using the above encoder, and is not described herein again. The feature vector obtained by coding the key value pair comprises the semantic information of the first text, so that the generated text can be more accurate in a scene in which the text with the voice information in the first text needs to be generated.
It can be understood that, in the step S201, a pre-trained key-value pair generation model may be directly used, and the first text is input and the corresponding key-value pair is directly output, which is not described herein again.
Optionally, the step S103 includes:
step S401, generating the nth component of the feature vector of the first text according to the first n characters in the first text until m components are obtained;
step S402, obtaining a feature vector of the first text according to the m components; wherein m is the number of characters in the first text.
In step S401, n is an integer greater than 0 and smaller than m, the first text is encoded by an encoding layer in an encoder, where the encoder includes m encoding layers, where m is the number of words in the first text, and at a time t, the t-th encoding layer of the encoder receives the t-th word and a vector input by the t-1-th encoding layer to generate a vector of the t-th layer. In this embodiment, the output of the coding layer at each time is taken as a component of the feature vector of the first text, where each component has the same size, and each exemplary component is a one-dimensional vector with a size of V, and then the feature vector of the first text is an m × V vector composed of m one-dimensional vectors with a size of V.
It can be understood that the above process of encoding the first text to obtain the feature vector of the first text and the obtained feature vector of the first text are examples, and practically any other encoding manner and the obtained feature vector of the first text may be applied to the embodiment of the present disclosure, and are not described herein again.
Step S104, obtaining a combined feature vector according to the feature vector of the input image and the feature vector of the first text;
in order to be able to obtain the text to be generated by inputting the image and the first text entered by the user, features of the image and features of said first text are combined in this step.
Optionally, the step S104 includes: and splicing the feature vector of the input image and the feature vector of the first text to obtain the joint feature vector.
In this embodiment, the feature vector of the input image and the feature vector of the first text are both one-dimensional vectors, and then the feature vector of the input image and the feature vector of the first text are spliced to form a joint feature vector, where the feature vector of the input image is a one-dimensional vector with a size of V, the feature vector of the first text is a one-dimensional vector with a size of W, and then the joint feature vector is a one-dimensional vector with a size of V + W, where V and W are both integers greater than 0. If the feature vector of the input image and/or the feature vector of the first text are not one-dimensional vectors, the feature vectors can be expanded into one-dimensional vectors and then spliced to obtain a joint feature vector.
Optionally, the step S104 includes:
step S501, respectively calculating the similarity of m components of the feature vector of the input image and the feature vector of the first text to obtain m similarities;
step S502, calculating the weight values of the m components according to the m similarity degrees to obtain m weight values;
step S503, calculating to obtain the joint feature vector according to the m weight values and the m components.
Illustratively, the feature vector of the input image is a one-dimensional vector with a size of V, the feature vector of the first text has m components, the m components are outputs of m encoding layers in the encoder, and each component is a one-dimensional vector with a size of V. Thus, in step S501, the similarity between the feature vector of the input image and each of the m components is calculated, and m similarities are obtained or a similarity vector with a size of m is obtained. Illustratively, the similarity is a cosine similarity; let m similarity respectively be c1,c2……,cmIn step S502, the weight values of the m components are calculated according to the m similarities to obtain m weight values, where:
Figure BDA0002584583110000091
wherein, aiWeight values representing the ith component, ciRepresenting the similarity of the ith component to the feature vector of the input image. Thus, the weight value for each component can be calculated, and the sum of the m weight values is 1, where 1 ≦ i ≦ m.
In step S503, the joint feature vector is calculated according to the m weight values and the m components. Because the weight value is calculated through the similarity, and the similarity is calculated through the feature vector of the input image, the weight value includes the information of the input image, and the information of the input image in the combined feature vector is obtained through the m weight values and the m components.
Further, the step S503 includes:
calculating m weight components according to each component and the weight value corresponding to the component;
and adding the m weight components to obtain the joint feature vector.
The above two steps can be expressed using the following formula:
Figure BDA0002584583110000092
wherein T isiThe i-th component of the feature vector representing the first text, ai*TiRepresents the ith weight component, and T' represents the joint feature vector obtained after the m weight components are added. Thus, the joint feature vector calculated from the components of a feature vector of an input image of size V and feature vectors of m first texts of size V is a joint feature vector of size V.
And step S105, decoding the joint feature vector to generate a second text.
Optionally, the step S105 includes: and inputting the joint feature vector into a decoder for decoding to obtain the second text.
In one embodiment, the decoder includes a plurality of decoding layers, each decoding layer is configured to output a word in the second text, and the joint feature vector and an output of a previous decoding layer in a current decoding layer are used as inputs of the current decoding layer to obtain the word output by the current decoding layer. It is understood that the decoding layers are merely time-conceptual partitions, that is, one decoding layer is multiplexed at multiple time instants, and the details are not repeated herein.
And the decoder outputs the probability of each character at each moment, selects the character corresponding to the value with the maximum probability as the output character at the moment, and continuously outputs the next character through the character. But such output can only output one text, in order to be able to output multiple texts to increase the diversity of the second text, a first constraint is added in the present disclosure at the decoder output.
Optionally, the decoding the joint feature vector input to a decoder to obtain the second text includes:
the decoder acquires the probability of outputting characters at the current moment;
acquiring a preset number of characters according to the probability;
and generating a plurality of second texts according to the characters with the preset number.
Illustratively, the output of the decoder includes the probabilities corresponding to 6000 characters, and then the first constraint limits the first K characters with the highest probability of selecting the first character to be the output characters at the current moment and the input characters at the next moment, so that K second texts can be obtained; or the first constraint limits the first K characters with the maximum probability to be selected at each moment as the output characters at the current moment and the input characters at the next moment, so that K can be obtainednA second text, wherein n represents the length of the second text, wherein K and n are both integers greater than 0. Thus, by setting the number of characters selected for each time input, a plurality of different second texts can be obtained.
Optionally, the decoder generates a plurality of second texts according to the first constraint, including:
acquiring a plurality of pre-designated characters at the current moment;
and generating the plurality of second texts according to the plurality of words.
In the optional embodiment, a plurality of characters are pre-designated as output characters for the current moment; for example, several words may be designated as the first output word, in which case, no matter what the probability of the first output word is, the words are limited to a fixed number of words, so that the second text designating the first word is obtained, and since a plurality of words are designated, the subsequent words may be generated by the plurality of words to generate a plurality of second texts.
In the above embodiment, the convolutional neural network, the encoder and the decoder generate sub-networks in the same text generation model. In this embodiment, the text generation model is trained by the following steps:
acquiring a training text set, wherein the training text set comprises a first image, a first training text and a second training text, the first training text is a first word description of the first image, and the second training text is a second word description of the first image;
initializing parameters of the text generation model;
inputting the first image and the first training text into a text generation model to be trained to obtain a predicted two-text;
calculating an error value from the predicted second text and the second training text;
updating parameters of the text generation model according to the error value;
and iterating the updating process of the parameters until a convergence condition is reached to obtain the text generation model.
By the text generation method, the description text related to the input image can be generated, and compared with the manual writing of the description text, the text generation method can more accurately and rapidly generate the description text of the image under the scene with a large number of input images, so that the labor is saved, and the efficiency is improved.
The embodiment of the disclosure discloses a text generation method, which comprises the following steps: acquiring an input image and a first text; extracting the features of the input image to obtain a feature vector of the input image; coding the first text to obtain a feature vector of the first text; obtaining a combined feature vector according to the feature vector of the input image and the feature vector of the first text; and decoding the joint feature vector to generate a second text. The method generates the combined feature vector through the image features and the text features, and generates the second text describing the image through decoding the training special vector, thereby solving the technical problems of time consumption and low efficiency in generating the image description information in the prior art.
In the above, although the steps in the above method embodiments are described in the above sequence, it should be clear to those skilled in the art that the steps in the embodiments of the present disclosure are not necessarily performed in the above sequence, and may also be performed in other sequences such as reverse, parallel, and cross, and further, on the basis of the above steps, other steps may also be added by those skilled in the art, and these obvious modifications or equivalents should also be included in the protection scope of the present disclosure, and are not described herein again.
Fig. 6 is a schematic structural diagram of an embodiment of a text generating apparatus provided in an embodiment of the present disclosure, and as shown in fig. 6, the apparatus 600 includes: an input module 601, a decimation module 602, an encoding module 603, a combination module 604 and a decoding module 605. Wherein the content of the first and second substances,
an input module 601, configured to obtain an input image and a first text;
an extraction module 602, configured to extract features of the input image to obtain a feature vector of the input image;
the encoding module 603 is configured to encode the first text to obtain a feature vector of the first text;
a combining module 604, configured to obtain a combined feature vector according to the feature vector of the input image and the feature vector of the first text;
a decoding module 605, configured to decode the joint feature vector to generate a second text.
Further, the extracting module 602 is further configured to:
and inputting the input image into a convolutional neural network to obtain a feature vector of the input image.
Further, the encoding module 603 is further configured to:
and inputting the first text into an encoder for encoding to obtain a feature vector of the first text.
Further, the combining module 604 is further configured to:
and splicing the feature vector of the input image and the feature vector of the first text to obtain the joint feature vector.
Further, the encoding module 603 is further configured to:
extracting texts of the first text to obtain a key value pair of the first text;
and coding the key value pair to obtain a feature vector of the first text.
Further, the encoding module 603 is further configured to:
performing word segmentation on the first text to obtain a word segmentation result;
and performing semantic analysis on the word segmentation result to obtain a word segmentation result corresponding to a preset key so as to generate the key value pair.
Further, the encoding module 603 is further configured to:
generating an nth component of a feature vector of the first text according to the first n words in the first text until m components are obtained;
obtaining a feature vector of the first text according to the m components; wherein m is the number of characters in the first text.
Further, the combining module 604 is further configured to:
respectively calculating the similarity of the feature vector of the input image and m components of the feature vector of the first text to obtain m similarities;
calculating the weight values of the m components according to the m similarity degrees to obtain m weight values;
and calculating to obtain the joint feature vector according to the m weight values and the m components.
Further, the combining module 604 is further configured to:
calculating m weight components according to each component and the weight value corresponding to the component;
and adding the m weight components to obtain the joint feature vector.
Further, the decoding module 605 is further configured to:
and inputting the joint feature vector into a decoder for decoding to obtain the second text.
The apparatus shown in fig. 6 can perform the method of the embodiment shown in fig. 1-5, and the detailed description of this embodiment can refer to the related description of the embodiment shown in fig. 1-5. The implementation process and technical effect of the technical solution refer to the descriptions in the embodiments shown in fig. 1 to 5, and are not described herein again.
Referring now to FIG. 7, shown is a schematic diagram of an electronic device 700 suitable for use in implementing embodiments of the present disclosure. The terminal device in the embodiments of the present disclosure may include, but is not limited to, a mobile terminal such as a mobile phone, a notebook computer, a digital broadcast receiver, a PDA (personal digital assistant), a PAD (tablet computer), a PMP (portable multimedia player), a vehicle terminal (e.g., a car navigation terminal), and the like, and a stationary terminal such as a digital TV, a desktop computer, and the like. The electronic device shown in fig. 7 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present disclosure.
As shown in fig. 7, electronic device 700 may include a processing means (e.g., central processing unit, graphics processor, etc.) 701 that may perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)702 or a program loaded from storage 708 into a Random Access Memory (RAM) 703. In the RAM 703, various programs and data necessary for the operation of the electronic apparatus 700 are also stored. The processing device 701, the ROM 702, and the RAM 703 are connected to each other by a bus 704. An input/output (I/O) interface 705 is also connected to bus 704.
Generally, the following devices may be connected to the I/O interface 705: input devices 706 including, for example, a touch screen, touch pad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; an output device 707 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, and the like; storage 708 including, for example, magnetic tape, hard disk, etc.; and a communication device 709. The communication means 709 may allow the electronic device 700 to communicate wirelessly or by wire with other devices to exchange data. While fig. 7 illustrates an electronic device 700 having various means, it is to be understood that not all illustrated means are required to be implemented or provided. More or fewer devices may alternatively be implemented or provided.
In particular, according to an embodiment of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program carried on a non-transitory computer readable medium, the computer program containing program code for performing the method illustrated by the flow chart. In such embodiments, the computer program may be downloaded and installed from a network via the communication means 709, or may be installed from the storage means 708, or may be installed from the ROM 702. The computer program, when executed by the processing device 701, performs the above-described functions defined in the methods of the embodiments of the present disclosure.
It should be noted that the computer readable medium in the present disclosure can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In contrast, in the present disclosure, a computer readable signal medium may comprise a propagated data signal with computer readable program code embodied therein, either in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, optical cables, RF (radio frequency), etc., or any suitable combination of the foregoing.
In some embodiments, the clients, servers may communicate using any currently known or future developed network protocol, such as HTTP (HyperText transfer protocol), and may be interconnected with any form or medium of digital data communication (e.g., a communications network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), the Internet (e.g., the Internet), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks), as well as any currently known or future developed network.
The computer readable medium may be embodied in the electronic device; or may exist separately without being assembled into the electronic device.
The computer readable medium carries one or more programs which, when executed by the electronic device, cause the electronic device to: perform any of the methods described in the embodiments of the present disclosure.
Computer program code for carrying out operations for the present disclosure may be written in any combination of one or more programming languages, including but not limited to an object oriented programming language such as Java, Smalltalk, C + +, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in the embodiments of the present disclosure may be implemented by software or hardware. Where the name of an element does not in some cases constitute a limitation on the element itself.
The functions described herein above may be performed, at least in part, by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field Programmable Gate Arrays (FPGAs), Application Specific Integrated Circuits (ASICs), Application Specific Standard Products (ASSPs), systems on a chip (SOCs), Complex Programmable Logic Devices (CPLDs), and the like.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
According to one or more embodiments of the present disclosure, there is provided a text generation method including:
acquiring an input image and a first text;
extracting the features of the input image to obtain a feature vector of the input image;
coding the first text to obtain a feature vector of the first text;
obtaining a combined feature vector according to the feature vector of the input image and the feature vector of the first text;
and decoding the joint feature vector to generate a second text.
Further, the extracting features of the input image to obtain a feature vector of the input image includes:
and inputting the input image into a convolutional neural network to obtain a feature vector of the input image.
Further, the encoding the first text to obtain a feature vector of the first text includes:
and inputting the first text into an encoder for encoding to obtain a feature vector of the first text.
Further, the obtaining a joint feature vector according to the feature vector of the input image and the feature vector of the first text includes:
and splicing the feature vector of the input image and the feature vector of the first text to obtain the joint feature vector.
Further, the encoding the first text to obtain a feature vector of the first text includes:
extracting texts of the first text to obtain a key value pair of the first text;
and coding the key value pair to obtain a feature vector of the first text.
Further, the extracting the first text to obtain the key-value pair of the first text includes:
performing word segmentation on the first text to obtain a word segmentation result;
and performing semantic analysis on the word segmentation result to obtain a word segmentation result corresponding to a preset key so as to generate the key value pair.
Further, the encoding the first text to obtain a feature vector of the first text includes:
generating an nth component of a feature vector of the first text according to the first n words in the first text until m components are obtained;
obtaining a feature vector of the first text according to the m components; wherein m is the number of characters in the first text.
Further, the obtaining a joint feature vector according to the feature vector of the input image and the feature vector of the first text includes:
respectively calculating the similarity of the feature vector of the input image and m components of the feature vector of the first text to obtain m similarities;
calculating the weight values of the m components according to the m similarity degrees to obtain m weight values;
and calculating to obtain the joint feature vector according to the m weight values and the m components.
Further, the obtaining the joint feature vector by calculating according to the m weight values and the m components includes:
calculating m weight components according to each component and the weight value corresponding to the component;
and adding the m weight components to obtain the joint feature vector.
Further, the decoding the joint feature vector to generate a second text includes:
and inputting the joint feature vector into a decoder for decoding to obtain the second text.
According to one or more embodiments of the present disclosure, there is provided a text generation apparatus including:
the input module is used for acquiring an input image and a first text;
the extraction module is used for extracting the features of the input image to obtain a feature vector of the input image;
the encoding module is used for encoding the first text to obtain a feature vector of the first text;
the combination module is used for obtaining a combination feature vector according to the feature vector of the input image and the feature vector of the first text;
and the decoding module is used for decoding the joint feature vector to generate a second text.
Further, the extraction module is further configured to:
and inputting the input image into a convolutional neural network to obtain a feature vector of the input image.
Further, the encoding module is further configured to:
and inputting the first text into an encoder for encoding to obtain a feature vector of the first text.
Further, the combination module is further configured to:
and splicing the feature vector of the input image and the feature vector of the first text to obtain the joint feature vector.
Further, the encoding module is further configured to:
extracting texts of the first text to obtain a key value pair of the first text;
and coding the key value pair to obtain a feature vector of the first text.
Further, the encoding module is further configured to:
performing word segmentation on the first text to obtain a word segmentation result;
and performing semantic analysis on the word segmentation result to obtain a word segmentation result corresponding to a preset key so as to generate the key value pair.
Further, the encoding module is further configured to:
generating an nth component of a feature vector of the first text according to the first n words in the first text until m components are obtained;
obtaining a feature vector of the first text according to the m components; wherein m is the number of characters in the first text.
Further, the combination module is further configured to:
respectively calculating the similarity of the feature vector of the input image and m components of the feature vector of the first text to obtain m similarities;
calculating the weight values of the m components according to the m similarity degrees to obtain m weight values;
and calculating to obtain the joint feature vector according to the m weight values and the m components.
Further, the combination module is further configured to:
calculating m weight components according to each component and the weight value corresponding to the component;
and adding the m weight components to obtain the joint feature vector.
Further, the decoding module is further configured to:
and inputting the joint feature vector into a decoder for decoding to obtain the second text. According to one or more embodiments of the present disclosure, there is provided an electronic device including: at least one processor; and a memory communicatively coupled to the at least one processor; wherein the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the text generation method of any of the preceding first aspects.
According to one or more embodiments of the present disclosure, there is provided a non-transitory computer-readable storage medium characterized by storing computer instructions for causing a computer to perform the text generation method of any one of the preceding first aspects.
The foregoing description is only exemplary of the preferred embodiments of the disclosure and is illustrative of the principles of the technology employed. It will be appreciated by those skilled in the art that the scope of the disclosure herein is not limited to the particular combination of features described above, but also encompasses other embodiments in which any combination of the features described above or their equivalents does not depart from the spirit of the disclosure. For example, the above features and (but not limited to) the features disclosed in this disclosure having similar functions are replaced with each other to form the technical solution.

Claims (13)

1. A text generation method, comprising:
acquiring an input image and a first text;
extracting the features of the input image to obtain a feature vector of the input image;
coding the first text to obtain a feature vector of the first text;
obtaining a combined feature vector according to the feature vector of the input image and the feature vector of the first text;
and decoding the joint feature vector to generate a second text.
2. The text generation method of claim 1, wherein said extracting features of the input image to obtain a feature vector of the input image comprises:
and inputting the input image into a convolutional neural network to obtain a feature vector of the input image.
3. The text generation method of claim 1, wherein said encoding the first text to obtain a feature vector of the first text comprises:
and inputting the first text into an encoder for encoding to obtain a feature vector of the first text.
4. The text generation method of claim 1, wherein the deriving a joint feature vector from the feature vector of the input image and the feature vector of the first text comprises:
and splicing the feature vector of the input image and the feature vector of the first text to obtain the joint feature vector.
5. The text generation method of claim 1, wherein said encoding the first text to obtain a feature vector of the first text comprises:
extracting texts of the first text to obtain a key value pair of the first text;
and coding the key value pair to obtain a feature vector of the first text.
6. The text generation method of claim 5, wherein the text extracting the first text to obtain key-value pairs of the first text comprises:
performing word segmentation on the first text to obtain a word segmentation result;
and performing semantic analysis on the word segmentation result to obtain a word segmentation result corresponding to a preset key so as to generate the key value pair.
7. The text generation method of claim 1, wherein said encoding the first text to obtain a feature vector of the first text comprises:
generating an nth component of a feature vector of the first text according to the first n words in the first text until m components are obtained;
obtaining a feature vector of the first text according to the m components; wherein m is the number of characters in the first text.
8. The text generation method of claim 7, wherein the deriving a joint feature vector from the feature vector of the input image and the feature vector of the first text comprises:
respectively calculating the similarity of the feature vector of the input image and m components of the feature vector of the first text to obtain m similarities;
calculating the weight values of the m components according to the m similarity degrees to obtain m weight values;
and calculating to obtain the joint feature vector according to the m weight values and the m components.
9. The text generation method of claim 8, wherein said calculating the joint feature vector according to the m weight values and the m components comprises:
calculating m weight components according to each component and the weight value corresponding to the component;
and adding the m weight components to obtain the joint feature vector.
10. The text generation method of claim 1, wherein said decoding the joint feature vector to generate a second text comprises:
and inputting the joint feature vector into a decoder for decoding to obtain the second text.
11. A text generation apparatus, comprising:
the input module is used for acquiring an input image and a first text;
the extraction module is used for extracting the features of the input image to obtain a feature vector of the input image;
the encoding module is used for encoding the first text to obtain a feature vector of the first text;
the combination module is used for obtaining a combination feature vector according to the feature vector of the input image and the feature vector of the first text;
and the decoding module is used for decoding the joint feature vector to generate a second text.
12. An electronic device, comprising:
a memory for storing computer readable instructions; and
a processor for executing the computer readable instructions such that the processor when executed implements the method of any of claims 1-10.
13. A non-transitory computer readable storage medium storing computer readable instructions which, when executed by a computer, cause the computer to perform the method of any one of claims 1-10.
CN202010677523.5A 2020-07-15 Text generation method and device and electronic equipment Active CN111898338B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010677523.5A CN111898338B (en) 2020-07-15 Text generation method and device and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010677523.5A CN111898338B (en) 2020-07-15 Text generation method and device and electronic equipment

Publications (2)

Publication Number Publication Date
CN111898338A true CN111898338A (en) 2020-11-06
CN111898338B CN111898338B (en) 2024-04-30

Family

ID=

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112270163A (en) * 2020-12-07 2021-01-26 北京沃东天骏信息技术有限公司 Text generation method and device and storage medium
CN112817604A (en) * 2021-02-18 2021-05-18 北京邮电大学 Android system control intention identification method and device, electronic equipment and storage medium

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20190250891A1 (en) * 2018-02-12 2019-08-15 Oracle International Corporation Automated code generation
CN110210499A (en) * 2019-06-03 2019-09-06 中国矿业大学 A kind of adaptive generation system of image, semantic description
CN110458242A (en) * 2019-08-16 2019-11-15 广东工业大学 A kind of iamge description generation method, device, equipment and readable storage medium storing program for executing
CN111008957A (en) * 2019-11-19 2020-04-14 北京推想科技有限公司 Medical information processing method and device
CN111046904A (en) * 2019-10-30 2020-04-21 中国科学院深圳先进技术研究院 Image description method, image description device and computer storage medium
CN111415740A (en) * 2020-02-12 2020-07-14 东北大学 Method and device for processing inquiry information, storage medium and computer equipment

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20190250891A1 (en) * 2018-02-12 2019-08-15 Oracle International Corporation Automated code generation
CN110210499A (en) * 2019-06-03 2019-09-06 中国矿业大学 A kind of adaptive generation system of image, semantic description
CN110458242A (en) * 2019-08-16 2019-11-15 广东工业大学 A kind of iamge description generation method, device, equipment and readable storage medium storing program for executing
CN111046904A (en) * 2019-10-30 2020-04-21 中国科学院深圳先进技术研究院 Image description method, image description device and computer storage medium
CN111008957A (en) * 2019-11-19 2020-04-14 北京推想科技有限公司 Medical information processing method and device
CN111415740A (en) * 2020-02-12 2020-07-14 东北大学 Method and device for processing inquiry information, storage medium and computer equipment

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112270163A (en) * 2020-12-07 2021-01-26 北京沃东天骏信息技术有限公司 Text generation method and device and storage medium
CN112270163B (en) * 2020-12-07 2021-09-10 北京沃东天骏信息技术有限公司 Text generation method and device and storage medium
CN112817604A (en) * 2021-02-18 2021-05-18 北京邮电大学 Android system control intention identification method and device, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
CN109902186B (en) Method and apparatus for generating neural network
CN112035743B (en) Data recommendation method and device, computer equipment and storage medium
CN111625645B (en) Training method and device for text generation model and electronic equipment
CN110826567B (en) Optical character recognition method, device, equipment and storage medium
CN113436620B (en) Training method of voice recognition model, voice recognition method, device, medium and equipment
CN110659639B (en) Chinese character recognition method and device, computer readable medium and electronic equipment
CN113327599B (en) Voice recognition method, device, medium and electronic equipment
US20240078385A1 (en) Method and apparatus for generating text
CN113157153A (en) Content sharing method and device, electronic equipment and computer readable storage medium
CN115908640A (en) Method and device for generating image, readable medium and electronic equipment
CN116128055A (en) Map construction method, map construction device, electronic equipment and computer readable medium
CN109816023B (en) Method and device for generating picture label model
CN113591490B (en) Information processing method and device and electronic equipment
CN114067327A (en) Text recognition method and device, readable medium and electronic equipment
CN110674813B (en) Chinese character recognition method and device, computer readable medium and electronic equipment
CN112752118A (en) Video generation method, device, equipment and storage medium
CN113761174A (en) Text generation method and device
CN111797822A (en) Character object evaluation method and device and electronic equipment
CN111898338B (en) Text generation method and device and electronic equipment
CN111581455B (en) Text generation model generation method and device and electronic equipment
CN115757933A (en) Recommendation information generation method, device, equipment, medium and program product
CN115129877A (en) Method and device for generating punctuation mark prediction model and electronic equipment
CN114495081A (en) Text recognition method and device, readable medium and electronic equipment
CN111611420B (en) Method and device for generating image description information
CN111898338A (en) Text generation method and device and electronic equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant