CN112860860A - Method and device for answering questions - Google Patents

Method and device for answering questions Download PDF

Info

Publication number
CN112860860A
CN112860860A CN201911191247.5A CN201911191247A CN112860860A CN 112860860 A CN112860860 A CN 112860860A CN 201911191247 A CN201911191247 A CN 201911191247A CN 112860860 A CN112860860 A CN 112860860A
Authority
CN
China
Prior art keywords
question
text
questioning
question text
feature
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.)
Pending
Application number
CN201911191247.5A
Other languages
Chinese (zh)
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 Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information 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 Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201911191247.5A priority Critical patent/CN112860860A/en
Publication of CN112860860A publication Critical patent/CN112860860A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • 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/33Querying
    • G06F16/332Query formulation
    • G06F16/3329Natural language query formulation or dialogue systems
    • 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
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F18/00Pattern recognition
    • G06F18/20Analysing
    • G06F18/21Design or setup of recognition systems or techniques; Extraction of features in feature space; Blind source separation
    • G06F18/214Generating training patterns; Bootstrap methods, e.g. bagging or boosting
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F18/00Pattern recognition
    • G06F18/20Analysing
    • G06F18/24Classification techniques
    • G06F18/241Classification techniques relating to the classification model, e.g. parametric or non-parametric approaches
    • G06F18/2411Classification techniques relating to the classification model, e.g. parametric or non-parametric approaches based on the proximity to a decision surface, e.g. support vector machines
    • 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
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/08Learning methods

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • General Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Artificial Intelligence (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Mathematical Physics (AREA)
  • Evolutionary Computation (AREA)
  • Computational Linguistics (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Molecular Biology (AREA)
  • Health & Medical Sciences (AREA)
  • Biomedical Technology (AREA)
  • Biophysics (AREA)
  • Bioinformatics & Computational Biology (AREA)
  • General Health & Medical Sciences (AREA)
  • Evolutionary Biology (AREA)
  • Computing Systems (AREA)
  • Bioinformatics & Cheminformatics (AREA)
  • Software Systems (AREA)
  • Databases & Information Systems (AREA)
  • Human Computer Interaction (AREA)
  • Machine Translation (AREA)

Abstract

The invention discloses a method and a device for answering questions, and relates to the technical field of computers. One embodiment of the method comprises: labeling each question text, and extracting a feature vector from each question text; training a neural network by taking the feature vector of each question text as input and taking the label of each question text as output to obtain a response model; determining an intention to ask a question, a slot position and a slot value corresponding to the slot position based on a feature vector of a to-be-answered question text input by a user and the answer model; and generating a reply text according to the questioning intention, the slot position and the corresponding slot value. The method and the device can solve the technical problem that the matched answer is incorrect due to the fact that the problem of the user cannot be accurately analyzed.

Description

Method and device for answering questions
Technical Field
The invention relates to the technical field of computers, in particular to a method and a device for answering questions.
Background
At present, the application of intelligent robots is becoming more and more widespread, wherein the question-and-answer robot is mainly used for hospitals, the foreground of companies, consultation platforms, lines and the like for users to consult. For example, many existing large hospitals are provided with question-answering robots at outpatient hall positions, the medical personnel can input own questions in front of the robots by voice, and the robots search answers of the questions through communication with the background server and provide the answers to the medical personnel; for another example, the user may ask a question to the robot when he/she browses an article on line or after buying an article, and the robot may automatically answer the question of the user.
In the process of implementing the invention, the inventor finds that at least the following problems exist in the prior art:
because the questions consulted by the user are various, the problems of the user cannot be accurately analyzed in the prior art, and the matched answers are not the answers really wanted by the user, so that the user experience is poor.
Disclosure of Invention
In view of this, embodiments of the present invention provide a method and an apparatus for answering questions, so as to solve the technical problem that the matched answer is incorrect due to the fact that the questions of the user cannot be accurately analyzed.
To achieve the above object, according to an aspect of an embodiment of the present invention, there is provided a method of answering a question, including:
labeling each question text, and extracting a feature vector from each question text; wherein the tags include an intent tag and a slot tag;
training a neural network by taking the feature vector of each question text as input and taking the label of each question text as output to obtain a response model;
determining the question intention, the slot position and the corresponding slot value based on the feature vector of the question text to be answered and the answer model;
and generating a reply text according to the questioning intention, the slot position and the corresponding slot value.
Optionally, extracting feature vectors from the respective question texts includes:
for each question text, extracting a feature vector by adopting the following method:
extracting single character features, word segmentation features and context features from the questioning text respectively;
and assembling the single character features, the word segmentation features and the context features into feature vectors.
Optionally, training a neural network with the feature vector of each question text as an input and the label of each question text as an output to obtain a response model, including:
mapping the feature vectors of the questioning texts into feature mathematical vectors;
and training a neural network based on the characteristic mathematical vectors corresponding to the questioning texts and the labels thereof to obtain a response model.
Optionally, mapping the feature vector of each question text into a feature mathematical vector, including:
for each question text, mapping the feature vector into a feature mathematical vector by the following method:
mapping each single character feature into a single character feature identifier based on a single character frequency dictionary;
respectively mapping each word segmentation characteristic to a word segmentation characteristic identifier based on a preset mapping rule;
and respectively mapping the context characteristics corresponding to the single characters into context characteristic identifiers based on the context frequency dictionary.
Optionally, a single character and a corresponding identifier thereof are recorded in the single character frequency dictionary, and the identifier of the single character describes a sequence number of the single character in the sequence from high to low in historical occurrence frequency; and/or the presence of a gas in the gas,
the context frequency dictionary is recorded with identifications corresponding to the contexts of the single words, and the identifications corresponding to the contexts describe sequence numbers of the contexts of the single words in a sequence from high to low.
Optionally, labeling each question text with a label, comprising:
respectively marking intention labels for the questioning texts;
respectively marking slot position labels on the question texts by adopting a sequence marking mode;
training a neural network by taking the feature vector of each question text as input and taking the label of each question text as output to obtain a response model, wherein the training comprises the following steps:
training a first neural network by taking the feature vector of each question text as input and taking the intention label of each question text as output to obtain an intention model;
training a second neural network by taking the feature vector of each question text as input and the slot position label of each question text as output so as to obtain a slot position extraction model;
wherein the answer model includes an intent model and a slot extraction model.
Optionally, generating a reply text based on the intention to ask, the slot and its corresponding slot value includes:
determining a dialect template according to the questioning intention, the slot position and the corresponding slot value;
and generating a reply text according to the phonetics template, or generating the reply text according to the phonetics template, the slot position and the corresponding slot value.
In addition, according to another aspect of an embodiment of the present invention, there is provided an apparatus for answering a question, including:
the processing module is used for marking labels on the questioning texts and extracting feature vectors from the questioning texts;
the training module is used for training a neural network by taking the feature vector of each question text as input and taking the label of each question text as output so as to obtain a response model;
the determining module is used for determining the questioning intention, the slot position and the corresponding slot value based on the feature vector of the questioning text to be answered and the answer model;
and the reply module is used for generating a reply text according to the questioning intention, the slot position and the corresponding slot value.
Optionally, the processing module is further configured to:
for each question text, extracting a feature vector by adopting the following method:
extracting single character features, word segmentation features and context features from the questioning text respectively;
and assembling the single character features, the word segmentation features and the context features into feature vectors.
Optionally, the training module is further configured to:
mapping the feature vectors of the questioning texts into feature mathematical vectors;
and training a neural network based on the characteristic mathematical vectors corresponding to the questioning texts and the labels thereof to obtain a response model.
Optionally, the training module is further configured to:
for each question text, mapping the feature vector into a feature mathematical vector by the following method:
mapping each single character feature into a single character feature identifier based on a single character frequency dictionary;
respectively mapping each word segmentation characteristic to a word segmentation characteristic identifier based on a preset mapping rule;
and respectively mapping the context characteristics corresponding to the single characters into context characteristic identifiers based on the context frequency dictionary.
Optionally, a single character and a corresponding identifier thereof are recorded in the single character frequency dictionary, and the identifier of the single character describes a sequence number of the single character in the sequence from high to low in historical occurrence frequency; and/or the presence of a gas in the gas,
the context frequency dictionary is recorded with identifications corresponding to the contexts of the single words, and the identifications corresponding to the contexts describe sequence numbers of the contexts of the single words in a sequence from high to low.
Optionally, the processing module is further configured to:
respectively marking intention labels for the questioning texts;
respectively marking slot position labels on the question texts by adopting a sequence marking mode;
the training module is further configured to:
training a first neural network by taking the feature vector of each question text as input and taking the intention label of each question text as output to obtain an intention model;
training a second neural network by taking the feature vector of each question text as input and the slot position label of each question text as output so as to obtain a slot position extraction model;
wherein the answer model includes an intent model and a slot extraction model.
Optionally, the reply module is further configured to:
determining a dialect template according to the questioning intention, the slot position and the corresponding slot value;
and generating a reply text according to the phonetics template, or generating the reply text according to the phonetics template, the slot position and the corresponding slot value.
According to another aspect of the embodiments of the present invention, there is also provided an electronic device, including:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any of the embodiments described above.
According to another aspect of the embodiments of the present invention, there is also provided a computer readable medium, on which a computer program is stored, which when executed by a processor implements the method of any of the above embodiments.
One embodiment of the above invention has the following advantages or benefits: because the intention label and the slot position label are marked on each question text, the characteristic vector is extracted from each question text, the neural network is trained, and the technical means of generating the reply text according to the determined question intention, the slot position and the corresponding slot value is adopted, the technical problem that the matched answer is incorrect because the problems of the user cannot be accurately analyzed in the prior art is solved. According to the embodiment of the invention, the extracted feature vector is used for accurately analyzing the question text of the user, and then the question intention, the slot position and the corresponding slot value are determined through the trained model, so that the correct answer text is generated based on the question intention, the slot position and the corresponding slot value, and the human-computer interaction experience of the user is effectively improved.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a schematic diagram of the main flow of a method of answering questions according to an embodiment of the present invention;
fig. 2 is a schematic diagram of a network structure of a Text _ CNN model according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of a network structure of a Bi _ LSTM _ CRF model according to an embodiment of the present invention;
FIG. 4 is a schematic diagram of a network structure of a response model according to an embodiment of the invention;
FIG. 5 is a diagram showing a main flow of a method of answering a question according to a referential embodiment of the present invention;
FIG. 6 is a schematic diagram of the main blocks of an apparatus for answering questions according to an embodiment of the present invention;
FIG. 7 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
fig. 8 is a schematic structural diagram of a computer system suitable for implementing a terminal device or a server according to an embodiment of the present invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
Fig. 1 is a schematic diagram of a main flow of a method of answering a question according to an embodiment of the present invention. As an embodiment of the present invention, as shown in fig. 1, the method of answering a question may include:
step 101, labeling each question text, and extracting feature vectors from each question text.
Firstly, a plurality of question texts are obtained as training samples, and then the question texts are labeled. In order to enrich the sample, non-questioning texts can be further obtained as training samples, and the non-questioning texts are labeled.
In the subsequent steps, the intention of the question, the slot position and the corresponding slot value are determined through the model, so the step 101 comprises marking the intention label for each question text; and respectively marking slot position labels on the question texts by adopting a sequence marking mode.
In the step of labeling the intention labels for each question text, according to different service scenarios, labeling labels, such as 1, 2, 3, 4, etc., or labels such as a, b, c, etc., for each question text, where the labels correspond to a certain service scenario (i.e., the intention of the user), which is not limited in this embodiment of the present invention.
For example, the service scenarios processed by the embodiment of the present invention include 7, which are respectively:
ACT _ COMMMODITY, which represents a specific COMMODITY query service scenario;
ACT _ ORDER, representing an ORDER query service scenario;
ACT _ DISCOUNT, which represents the service scene of the fuzzy preferential query;
ACT _ SPECIFY _ DISCOUNT, which represents a specific preferential query service scene;
ACT _ AFTER _ SALES, which represents the business scene of AFTER-SALES service;
ACT _ SHORTCUT, which represents a direct service scene of the total station;
ACT _ UNKNOWN, indicating UNKNOWN.
The 7 service scenes can be respectively marked as 1, 2, 3, 4, 5, 6 and 7, and are used as labels of a deep learning model sample training set.
In the step of marking the slot position labels on the question texts respectively by using the sequence marking mode, a BIO sequence marking mode (B-begin, I-interior, O-exterior) or a BIO sequence marking mode (B-begin, I-interior, O-exterior, E-end, S-single) may be used to mark the slot position labels on the question texts respectively, and any mode may be configured to mark the question texts as required. Wherein B denotes the beginning of the slot, I denotes the middle of the slot, O denotes others, E denotes the end of the slot, and S denotes a single-word slot, optionally the slot includes at least one of: article words, brand words, modifiers, gender. Wherein, the modifier can be adjectives, adverbs and the like. For example, the question text is "I want to buy Hua as a mobile phone", the Hua is extracted as a brand word, and the mobile phone is an article word.
The following is described in detail with the biees sequence notation mode, for example as follows:
0 O
1 I-product
2 B-product
3 E-product
4 I-brand
5 B-wanted_deco
6 E-wanted_deco
7 B-brand
8 E-brand
9 I-wanted_deco
10 S-product
11 S-wanted_deco
12 S-brand
then the "writing case" can be marked as: 213, "pink" may be labeled 56, and so on, and will not be described further.
Optionally, in the step of extracting the feature vector from each question text, for each question text, the following method may be adopted to extract the feature vector: extracting single character features, word segmentation features and context features from the questioning text respectively; and assembling the single character features, the word segmentation features and the context features into feature vectors. The embodiment of the invention assembles the single character characteristic, the word segmentation characteristic and the context characteristic into the characteristic vector, and can determine the characteristic by combining the context, thereby improving the determination accuracy of the model.
Example (c): "I want to buy a dress. The individual character of "is as follows:
char _ inputs [ [ i, want, buy, piece, link, dress, skirt ]. ]]
In the step of extracting the word segmentation characteristics, word segmentation can be performed through a word segmentation tool such as jieba or standardscorenLP. Example (c): "I want to go to the business mall to buy a dress. "the word segmentation result is: "i", "want", "go", "business", "shopping", "center", "buy", "dress", ". ", the word segmentation characteristics of the quiz text are as follows:
word inputs [ [ i, want, go, business, shopping, center, buy, dress ]. ]]
In the step of extracting the context feature, the context feature corresponding to each individual character in the question text may be extracted based on a preset sliding window. Assume that the size of the sliding window is 5, i.e., context _ windows is 5. Taking the template specification w [ x ] ═ as the template, we will "i want to buy one-piece dress. "processing into a context format, where x is the relative position, yields the following context characteristics:
i [ 'w [ -2] = ],' w [ -1] ═ s >, 'w [0] ═ I', 'w [1] ═ thought', 'w [2] ═ buy' ]
Want [ ' w [ -2] ═ s >, ' w [ -1] ═ i ', ' w [0] ═ want ', ' w [1] ═ buy ', ' w [2] ═ one ' ]
The formula includes [ 'w [ -2] ═ me', 'w [ -1] ═ me', 'w [0] ═ me', 'w [1] ═ piece', 'w [2] ═ even' ]
The term "w [ -2], 'w [ -1],' w [0], 'w [1],' w [2], 'clothes' ]
Even [ 'w [ -2] }, [ -1] }, [ -0 ] }, [ -1] }, [ -a garment, [ -2] }, [ ], and a skirt' ]
Clothes [ 'w [ -2] ] [,' w [ -1] ] ═ even ',' w [0] ] ═ clothes ',' w [1] ═ skirt ',' w [2] ] [ ]
Skirt [ 'w [ -2] ═ even', 'w [ -1] ═ coat', 'w [0] ═ skirt', 'w [1] ═', 'w [2] ═ s' ]
. 'w-2' -skirt ',' w-1 '-skirt', 'w [0 ]', 'w [1 ]', 'w [2 ]' ]
For example, in the prior art, the feature vectors of an "apple" in an "i want to buy an apple mobile phone" and an "apple" in a "i want to eat an apple" are the same, and the feature vectors of the two "apples" are different by extracting through the extraction method of the present invention, so that the present invention extracts the single character feature, the word segmentation feature and the context feature from the question text respectively, and can accurately analyze the question of the user.
And 102, taking the feature vectors of the question texts as input and the labels of the question texts as output, and training a neural network to obtain a response model.
In this step, the neural network is trained by using the feature vectors and labels corresponding to the respective question texts in step 101, so as to obtain a response model. Optionally, step 102 may comprise: mapping the feature vectors of the questioning texts into feature mathematical vectors; and training a neural network based on the characteristic mathematical vectors corresponding to the questioning texts and the labels thereof to obtain a response model. Mapping the eigenvectors into eigen mathematical vectors facilitates updating the weights of the model and thus facilitates convergence of the model.
Optionally, in the step of mapping the feature vector into a feature mathematical vector, for each question text, the feature vector is mapped into the feature mathematical vector by the following method: mapping each single character feature into a single character feature identifier based on a single character frequency dictionary; respectively mapping each word segmentation characteristic to a word segmentation characteristic identifier based on a preset mapping rule; and respectively mapping the context characteristics corresponding to the single characters into context characteristic identifiers based on the context frequency dictionary.
The single character frequency dictionary and the context frequency dictionary need to be common in advance, and single characters, contexts and the like with high occurrence frequency are generally recorded. Optionally, the single word frequency dictionary is recorded with a single word and a corresponding identifier thereof, and the identifier of the single word describes a sequence number of the single word in the sequence from high to low in historical occurrence frequency. For example, a single character frequency dictionary of chinese characters needs to be established in advance, 5000 commonly used chinese characters are entered into the single character frequency dictionary, sorting is performed from high to low according to the historical occurrence frequency of each chinese character, and the sorting sequence number is used as the identifier corresponding to each chinese character. Therefore, the common Chinese characters can be mapped to a certain mark and can be trained through word2Vector in advance. And common punctuation marks or English can also have corresponding marks. For a single word not entered in the dictionary, it may be mapped to < UNK > uniformly, for example, 5001 may be used as an identifier (i.e., a single-word feature ID). It should be noted that, in the embodiment of the present invention, the single character may be a Chinese character or a punctuation mark.
Example (c): "I want to buy a dress. "can be mapped as the following single character feature identifier:
char_inputs=[[3,14,6,121,444,45,272,2]]
in the step of mapping each participle feature to a participle feature identifier, the mapping rule may be: if the single character is present, the mapping is 0; if the word is used, the first word is mapped to 1, the middle word is mapped to 2, and the last word is mapped to 3.
Example (c): "I want to go to the business mall to buy a dress. "can be mapped to the following word segmentation feature identifications:
word_inputs=[[0,0,0,1,2,1,2,1,2,0,1,2,3,0]]
optionally, the context frequency dictionary is recorded with an identifier corresponding to a context of a single word, where the identifier corresponding to the context describes a sequence number of the context of the single word in a sequence from high to low in historical occurrence frequency. The context frequency dictionary also needs to be established in advance, the context of common single characters and the corresponding identification thereof are recorded in the context frequency dictionary, the historical occurrence frequency of the context is sequenced from high to low, and the sequencing serial number is used as the identification corresponding to each context. These common contexts can therefore all be mapped to a certain identity.
For example, "i want to buy a piece of one-dress according to the context frequency dictionary (ner _ context _ fact. "to the corresponding identity (i.e. context feature ID):
w 2 is connected to 850
w 1 is linked 851
w 2 ═ coat 852
w 0 ═ or 853
w 1 ═ coat 854
855 skirt w 2 ═ w
w < -1 > -link 856
w 0 ═ clothing 857
The complete context feature vector is then as follows:
context_inputs=[[[1,2,62,204,172],[1,65,205,174,207],[68,206,177,209,850],[208,181,211,851,852],[185,214,853,854,855],[215,856,857,858,5296],[859,860,861,4600,44],[862,863,4601,48,44]]]
optionally, step 102 may comprise: training a first neural network by taking the feature vector of each question text as input and taking the intention label of each question text as output to obtain an intention model; and training a second neural network by taking the feature vector of each question text as input and the slot position label of each question text as output so as to obtain a slot position extraction model. Wherein the answer model includes an intent model and a slot extraction model.
And 103, determining the questioning intention, the slot position and the corresponding slot value based on the feature vector of the questioning text to be answered and the answer model.
When a user inputs a text to be answered, extracting a feature vector from the text to be answered, wherein the extracting method is the same as the step 101, and then inputting the feature vector of the text to be answered into an answer model trained through the public step 102, so that the intention of asking a question, the slot position and the corresponding slot value are output. It should be noted that if the user inputs voice data, the voice data needs to be converted into text data.
And 104, generating a reply text according to the questioning intention, the slot position and the corresponding slot value.
In step (ii), an accurate reply text can be generated based on the intent to ask, the slot position and the slot value corresponding thereto determined in step (103). Optionally, step 104 may include: determining a dialect template according to the questioning intention, the slot position and the corresponding slot value; and generating a reply text according to the phonetics template, or generating the reply text according to the phonetics template, the slot position and the corresponding slot value. In some embodiments, the dialogical template determined from the intent of asking the question, the slot and its corresponding slot value may be directly used as a reply text, such as "ask what is your gender? "," ask for how much of your age? "good, will process you as soon as possible! "and the like. In some embodiments, a slot value may need to be further populated in the phonics template determined from the intent to ask, the slot and its corresponding slot value, and thus a reply text may be generated from the phonics template, the slot and its corresponding slot value.
According to the various embodiments, the invention can be seen that the technical means of generating the reply text according to the determined question intention, slot position and the corresponding slot value thereof by marking the intention label and slot position label on each question text and extracting the feature vector from each question text to train the neural network solves the technical problem that the matched answer is incorrect because the problems of the user cannot be accurately analyzed in the prior art. According to the embodiment of the invention, the extracted feature vector is used for accurately analyzing the question text of the user, and then the question intention, the slot position and the corresponding slot value are determined through the trained model, so that the correct answer text is generated based on the question intention, the slot position and the corresponding slot value, and the human-computer interaction experience of the user is effectively improved.
In another embodiment of the present invention, two neural networks may be trained, one for determining the intention to ask a question, and the other for determining the slot position and its corresponding slot value, which is beneficial to improving the accuracy of the answer.
Alternatively, the first neural network may be a Text _ CNN (convolutional neural network) model, whose network structure is shown in fig. 2, and the input layer is used for receiving a feature vector of a questioning Text; the Embedding layer (Embedding) is used for mapping the feature vector of the questioning text into a feature mathematical vector; convolution layers (Conv1D) were convolved with convolution kernel vectors of 3 × 3,5 × 5,1 × 1, respectively; the Maxpooling layer is the largest pooling layer; the Concat layer is used for splicing the pooled vectors; the Flatten layer is used for flattening the spliced vector; and after entering the full connection layer, outputting the intention label through the output layer.
Alternatively, the second neural network may be an entity recognition (NER) model, such as a Bi _ LSTM _ CRF model, whose network structure is shown in fig. 3, and the input layer is used for receiving the feature vector of the questioning text; the Embedding layer (Embedding) is used for mapping the feature vector of the questioning text into a feature mathematical vector; the bidirectional LSTM (Long Short Term Memory) layer is used for extracting text sequence relation and front-back dependency; a CRF (conditional random field) layer is used for sequence determination; and finally, outputting the slot values corresponding to the equal slot positions of the article words, the brand words and the modifiers through an output layer.
In another embodiment of the present invention, only one neural network may be trained, as shown in fig. 4, the input layers in fig. 2 and fig. 3 are merged into one layer, and the Embedding layer is also merged into one layer, so that the questioning intention, the slot position, and the corresponding slot value can be accurately determined, and details are not repeated.
Fig. 5 is a schematic diagram of a main flow of a method of answering a question according to a referential embodiment of the present invention.
Step 501, respectively marking an intention label for each question text, and respectively marking a slot position label for each question text by adopting a sequence marking mode.
In the step of labeling the intention labels for the respective question texts, labels, such as 1, 2, 3, 4, etc., may also be labels a, b, c, etc., are labeled for the respective question texts according to different business scenarios, and these labels correspond to a certain business scenario (i.e., the user's intention to ask). The slot position labels can be respectively marked on the questioning texts by adopting a BIO sequence marking mode (B-begin, I-inside, O-outside) or a BIOES sequence marking mode (B-begin, I-inside, O-outside, E-end, S-single), and any mode can be configured to mark the questioning texts according to needs.
Step 502, extracting feature vectors from each question text.
For each question text, the feature vector can be extracted by adopting the following method: extracting single character features, word segmentation features and context features from the questioning text respectively; and assembling the single character features, the word segmentation features and the context features into feature vectors. The embodiment of the invention assembles the single character characteristic, the word segmentation characteristic and the context characteristic into the characteristic vector, and can determine the characteristic by combining the context, thereby improving the determination accuracy of the model.
Step 503, taking the feature vector of each question text as input, taking the intention label of each question text as output, and training a first neural network to obtain an intention model.
And step 504, training a second neural network by taking the feature vector of each question text as input and the slot position label of each question text as output so as to obtain a slot position extraction model.
Step 505, extracting a feature vector from the question text to be replied.
When the user inputs the text to be replied, the feature vector is extracted from the text to be replied, and the extraction method is the same as the step 502.
Step 506, the feature vectors of the text to be answered are respectively input into the intention model and the slot position extraction model, and the intention of asking questions, the slot position and the corresponding slot value are respectively determined.
And 507, generating a reply text according to the questioning intention, the slot position and the corresponding slot value.
Optionally, determining a dialect template according to the intention of asking, the slot position and the slot value corresponding to the slot position; a reply text is then generated from the phonetics template. Optionally, determining a dialect template according to the intention of asking, the slot position and the slot value corresponding to the slot position; and then generating a reply text according to the phonetics template, the slot position and the corresponding slot value.
It should be noted that, step 501 and step 502 may be executed simultaneously, or step 501 may be executed first and then step 502 is executed, or step 502 may be executed first and then step 501 is executed. Step 503 and step 504 may be executed simultaneously, or step 503 may be executed first and then step 504 may be executed.
In addition, in one embodiment of the present invention, the detailed implementation of the method for answering a question is described in detail in the above-mentioned method for answering a question, and therefore the repeated description is omitted.
Fig. 6 is a schematic diagram of main blocks of an apparatus for answering questions according to an embodiment of the present invention, and as shown in fig. 6, the apparatus 600 for answering questions includes a processing module 601, a training module 602, a determining module 603, and an answering module 604. The processing module 601 is configured to mark a label for each question text and extract a feature vector from each question text; the training module 602 is configured to train a neural network with the feature vectors of the respective question texts as inputs and the labels of the respective question texts as outputs to obtain a response model; the determining module 603 is configured to determine an intention to ask a question, a slot position, and a slot value corresponding to the intention, the slot position, and the slot value based on the feature vector of the question text to be answered and the answer model; the reply module 604 is configured to generate a reply text according to the intention to ask the question, the slot position, and the slot value corresponding to the slot position.
Optionally, the processing module 601 is further configured to:
for each question text, extracting a feature vector by adopting the following method:
extracting single character features, word segmentation features and context features from the questioning text respectively;
and assembling the single character features, the word segmentation features and the context features into feature vectors.
Optionally, the training module 602 is further configured to:
mapping the feature vectors of the questioning texts into feature mathematical vectors;
and training a neural network based on the characteristic mathematical vectors corresponding to the questioning texts and the labels thereof to obtain a response model.
Optionally, the training module 602 is further configured to:
for each question text, mapping the feature vector into a feature mathematical vector by the following method:
mapping each single character feature into a single character feature identifier based on a single character frequency dictionary;
respectively mapping each word segmentation characteristic to a word segmentation characteristic identifier based on a preset mapping rule;
and respectively mapping the context characteristics corresponding to the single characters into context characteristic identifiers based on the context frequency dictionary.
Optionally, a single character and a corresponding identifier thereof are recorded in the single character frequency dictionary, and the identifier of the single character describes a sequence number of the single character in the sequence from high to low in historical occurrence frequency; and/or the presence of a gas in the gas,
the context frequency dictionary is recorded with identifications corresponding to the contexts of the single words, and the identifications corresponding to the contexts describe sequence numbers of the contexts of the single words in a sequence from high to low.
Optionally, the processing module 601 is further configured to:
respectively marking intention labels for the questioning texts;
respectively marking slot position labels on the question texts by adopting a sequence marking mode;
the training module 602 is further configured to:
training a first neural network by taking the feature vector of each question text as input and taking the intention label of each question text as output to obtain an intention model;
training a second neural network by taking the feature vector of each question text as input and the slot position label of each question text as output so as to obtain a slot position extraction model;
wherein the answer model includes an intent model and a slot extraction model.
Optionally, the reply module 604 is further configured to:
determining a dialect template according to the questioning intention, the slot position and the corresponding slot value;
and generating a reply text according to the phonetics template, or generating the reply text according to the phonetics template, the slot position and the corresponding slot value.
According to the various embodiments, the invention can be seen that the technical means of generating the reply text according to the determined question intention, slot position and the corresponding slot value thereof by marking the intention label and slot position label on each question text and extracting the feature vector from each question text to train the neural network solves the technical problem that the matched answer is incorrect because the problems of the user cannot be accurately analyzed in the prior art. According to the embodiment of the invention, the extracted feature vector is used for accurately analyzing the question text of the user, and then the question intention, the slot position and the corresponding slot value are determined through the trained model, so that the correct answer text is generated based on the question intention, the slot position and the corresponding slot value, and the human-computer interaction experience of the user is effectively improved.
It should be noted that, in the implementation of the apparatus for answering questions of the present invention, the above method for answering questions has been described in detail, and therefore, the repeated content herein will not be described again.
Fig. 7 illustrates an exemplary system architecture 700 to which the method of answering questions or the apparatus for answering questions of embodiments of the present invention may be applied.
As shown in fig. 7, the system architecture 700 may include terminal devices 701, 702, 703, a network 704, and a server 705. The network 704 serves to provide a medium for communication links between the terminal devices 701, 702, 703 and the server 705. Network 704 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
A user may use the terminal devices 701, 702, 703 to interact with a server 704 over a network 704 to receive or send messages or the like. The terminal devices 701, 702, 703 may have installed thereon various communication client applications, such as a shopping-like application, a web browser application, a search-like application, an instant messaging tool, a mailbox client, social platform software, etc. (by way of example only).
The terminal devices 701, 702, 703 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 705 may be a server providing various services, such as a background management server (for example only) providing support for shopping websites browsed by users using the terminal devices 701, 702, 703. The background management server may analyze and otherwise process the received data such as the item information query request, and feed back a processing result (for example, target push information, item information — just an example) to the terminal device.
It should be noted that the method for answering questions provided by the embodiment of the present invention is generally executed by the server 705, and accordingly, the device for answering questions is generally disposed in the server 705. The method for answering questions provided by the embodiment of the present invention may also be executed by the terminal devices 701, 702, and 703, and accordingly, the apparatus for answering questions may be disposed in the terminal devices 701, 702, and 703.
It should be understood that the number of terminal devices, networks, and servers in fig. 7 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 8, shown is a block diagram of a computer system 800 suitable for use with a terminal device implementing an embodiment of the present invention. The terminal device shown in fig. 8 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 8, the computer system 800 includes a Central Processing Unit (CPU)801 that can perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)802 or a program loaded from a storage section 808 into a Random Access Memory (RAM) 803. In the RAM803, various programs and data necessary for the operation of the system 800 are also stored. The CPU 801, ROM 802, and RAM803 are connected to each other via a bus 804. An input/output (I/O) interface 805 is also connected to bus 804.
The following components are connected to the I/O interface 805: an input portion 806 including a keyboard, a mouse, and the like; an output section 807 including a signal such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 808 including a hard disk and the like; and a communication section 809 including a network interface card such as a LAN card, a modem, or the like. The communication section 809 performs communication processing via a network such as the internet. A drive 810 is also connected to the I/O interface 805 as necessary. A removable medium 811 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 810 as necessary, so that a computer program read out therefrom is mounted on the storage section 808 as necessary.
In particular, according to the embodiments 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 article comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated by the flow chart. In such an embodiment, the computer program can be downloaded and installed from a network through the communication section 809 and/or installed from the removable medium 811. The computer program executes the above-described functions defined in the system of the present invention when executed by the Central Processing Unit (CPU) 801.
It should be noted that the computer readable medium shown in the present invention 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 invention, 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 the present invention, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, 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: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program articles according to various embodiments of the present invention. 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 or flowchart illustration, and combinations of blocks in the block diagrams 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 modules described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor includes a processing module, a training module, a determining module, and a replying module, where the names of the modules do not in some cases constitute a limitation on the modules themselves.
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise: labeling each question text, and extracting a feature vector from each question text; wherein the tags include an intent tag and a slot tag; training a neural network by taking the feature vector of each question text as input and taking the label of each question text as output to obtain a response model; determining the question intention, the slot position and the corresponding slot value based on the feature vector of the question text to be answered and the answer model; and generating a reply text according to the questioning intention, the slot position and the corresponding slot value.
According to the technical scheme of the embodiment of the invention, because the intention label and the slot position label are marked for each question text, and the characteristic vector is extracted from each question text to train the neural network, the technical means of generating the reply text according to the determined question intention, the slot position and the corresponding slot value is adopted, the technical problem that the matched answer is incorrect because the problems of the user cannot be accurately analyzed in the prior art is solved. According to the embodiment of the invention, the extracted feature vector is used for accurately analyzing the question text of the user, and then the question intention, the slot position and the corresponding slot value are determined through the trained model, so that the correct answer text is generated based on the question intention, the slot position and the corresponding slot value, and the human-computer interaction experience of the user is effectively improved.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (10)

1. A method of answering questions, comprising:
labeling each question text, and extracting a feature vector from each question text; wherein the tags include an intent tag and a slot tag;
training a neural network by taking the feature vector of each question text as input and taking the label of each question text as output to obtain a response model;
determining the question intention, the slot position and the corresponding slot value based on the feature vector of the question text to be answered and the answer model;
and generating a reply text according to the questioning intention, the slot position and the corresponding slot value.
2. The method of claim 1, wherein extracting feature vectors from the respective questioning texts comprises:
for each question text, extracting a feature vector by adopting the following method:
extracting single character features, word segmentation features and context features from the questioning text respectively;
and assembling the single character features, the word segmentation features and the context features into feature vectors.
3. The method of claim 2, wherein training a neural network with the feature vectors of the respective question texts as input and the labels of the respective question texts as output to obtain a response model comprises:
mapping the feature vectors of the questioning texts into feature mathematical vectors;
and training a neural network based on the characteristic mathematical vectors corresponding to the questioning texts and the labels thereof to obtain a response model.
4. The method of claim 3, wherein mapping the feature vectors of the respective questioning texts to feature mathematical vectors comprises:
for each question text, mapping the feature vector into a feature mathematical vector by the following method:
mapping each single character feature into a single character feature identifier based on a single character frequency dictionary;
respectively mapping each word segmentation characteristic to a word segmentation characteristic identifier based on a preset mapping rule;
and respectively mapping the context characteristics corresponding to the single characters into context characteristic identifiers based on the context frequency dictionary.
5. The method of claim 4, wherein a single word and a corresponding identifier thereof are recorded in the single word frequency dictionary, and the identifier of the single word describes a sequence number of the single word from high to low in historical occurrence frequency; and/or the presence of a gas in the gas,
the context frequency dictionary is recorded with identifications corresponding to the contexts of the single words, and the identifications corresponding to the contexts describe sequence numbers of the contexts of the single words in a sequence from high to low.
6. The method of claim 1, wherein tagging each question text comprises:
respectively marking intention labels for the questioning texts;
respectively marking slot position labels on the question texts by adopting a sequence marking mode;
training a neural network by taking the feature vector of each question text as input and taking the label of each question text as output to obtain a response model, wherein the training comprises the following steps:
training a first neural network by taking the feature vector of each question text as input and taking the intention label of each question text as output to obtain an intention model;
training a second neural network by taking the feature vector of each question text as input and the slot position label of each question text as output so as to obtain a slot position extraction model;
wherein the answer model includes an intent model and a slot extraction model.
7. The method of claim 1, wherein generating a reply text based on the intent to ask, the slot, and its corresponding slot value comprises:
determining a dialect template according to the questioning intention, the slot position and the corresponding slot value;
and generating a reply text according to the phonetics template, or generating the reply text according to the phonetics template, the slot position and the corresponding slot value.
8. An apparatus for answering questions, comprising:
the processing module is used for marking labels on the questioning texts and extracting feature vectors from the questioning texts;
the training module is used for training a neural network by taking the feature vector of each question text as input and taking the label of each question text as output so as to obtain a response model;
the determining module is used for determining the questioning intention, the slot position and the corresponding slot value based on the feature vector of the questioning text to be answered and the answer model;
and the reply module is used for generating a reply text according to the questioning intention, the slot position and the corresponding slot value.
9. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-7.
10. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-7.
CN201911191247.5A 2019-11-28 2019-11-28 Method and device for answering questions Pending CN112860860A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911191247.5A CN112860860A (en) 2019-11-28 2019-11-28 Method and device for answering questions

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911191247.5A CN112860860A (en) 2019-11-28 2019-11-28 Method and device for answering questions

Publications (1)

Publication Number Publication Date
CN112860860A true CN112860860A (en) 2021-05-28

Family

ID=75995550

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911191247.5A Pending CN112860860A (en) 2019-11-28 2019-11-28 Method and device for answering questions

Country Status (1)

Country Link
CN (1) CN112860860A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113852605A (en) * 2021-08-29 2021-12-28 北京工业大学 Protocol format automatic inference method and system based on relational reasoning

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113852605A (en) * 2021-08-29 2021-12-28 北京工业大学 Protocol format automatic inference method and system based on relational reasoning
CN113852605B (en) * 2021-08-29 2023-09-22 北京工业大学 Protocol format automatic inference method and system based on relation reasoning

Similar Documents

Publication Publication Date Title
CN112685565B (en) Text classification method based on multi-mode information fusion and related equipment thereof
US11151177B2 (en) Search method and apparatus based on artificial intelligence
CN107241260B (en) News pushing method and device based on artificial intelligence
CN111368548A (en) Semantic recognition method and device, electronic equipment and computer-readable storage medium
CN111709240A (en) Entity relationship extraction method, device, equipment and storage medium thereof
CN106919711B (en) Method and device for labeling information based on artificial intelligence
US11741094B2 (en) Method and system for identifying core product terms
CN108280200B (en) Method and device for pushing information
CN111666766B (en) Data processing method, device and equipment
CN111159409B (en) Text classification method, device, equipment and medium based on artificial intelligence
CN111046656A (en) Text processing method and device, electronic equipment and readable storage medium
US11030405B2 (en) Method and device for generating statement
CN107958078A (en) Information generating method and device
CN113590776A (en) Text processing method and device based on knowledge graph, electronic equipment and medium
CN109522399B (en) Method and apparatus for generating information
US20220121668A1 (en) Method for recommending document, electronic device and storage medium
CN109190123B (en) Method and apparatus for outputting information
CN110874534B (en) Data processing method and data processing device
CN111639162A (en) Information interaction method and device, electronic equipment and storage medium
CN111738791B (en) Text processing method, device, equipment and storage medium
CN113836316B (en) Processing method, training method, device, equipment and medium for ternary group data
CN110807097A (en) Method and device for analyzing data
CN111538817A (en) Man-machine interaction method and device
CN111026849B (en) Data processing method and device
CN112860860A (en) Method and device for answering questions

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