CN112632406A - Query method and device, electronic equipment and storage medium - Google Patents

Query method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN112632406A
CN112632406A CN202011078854.3A CN202011078854A CN112632406A CN 112632406 A CN112632406 A CN 112632406A CN 202011078854 A CN202011078854 A CN 202011078854A CN 112632406 A CN112632406 A CN 112632406A
Authority
CN
China
Prior art keywords
word
space
vector
spatial
words
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
CN202011078854.3A
Other languages
Chinese (zh)
Other versions
CN112632406B (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.)
China Mobile Communications Group Co Ltd
MIGU Culture Technology Co Ltd
Original Assignee
China Mobile Communications Group Co Ltd
MIGU Culture 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 China Mobile Communications Group Co Ltd, MIGU Culture Technology Co Ltd filed Critical China Mobile Communications Group Co Ltd
Priority to CN202011078854.3A priority Critical patent/CN112632406B/en
Publication of CN112632406A publication Critical patent/CN112632406A/en
Application granted granted Critical
Publication of CN112632406B publication Critical patent/CN112632406B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/953Querying, e.g. by the use of web search engines
    • G06F16/9537Spatial or temporal dependent retrieval, e.g. spatiotemporal queries
    • 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/3331Query processing
    • G06F16/334Query execution
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/953Querying, e.g. by the use of web search engines
    • G06F16/9538Presentation of query results
    • 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
    • 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

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Computational Linguistics (AREA)
  • Health & Medical Sciences (AREA)
  • Artificial Intelligence (AREA)
  • General Health & Medical Sciences (AREA)
  • Biomedical Technology (AREA)
  • Computing Systems (AREA)
  • Molecular Biology (AREA)
  • Evolutionary Computation (AREA)
  • Mathematical Physics (AREA)
  • Software Systems (AREA)
  • Biophysics (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the invention provides a query method, a query device, electronic equipment and a storage medium; the method comprises the following steps: determining a space area corresponding to a query request according to position information when the user initiates the query request; searching a candidate query result set corresponding to the query request in the space region according to the text description information of the query request; determining a feature vector of text description information of the query request and a feature vector of each candidate query result in the candidate query result set according to a preset mapping relation between words and word embedding vectors; and sorting and returning each candidate query result in the candidate query result set to the user according to the distance between the feature vector of each candidate query result in the candidate query result set and the feature vector of the text description information of the query request.

Description

Query method and device, electronic equipment and storage medium
Technical Field
The present invention relates to the field of text processing, and in particular, to a query method, a query device, an electronic device, and a storage medium.
Background
When a query is performed on a computer, a word embedding method is usually adopted to calculate a feature vector of a word to be queried and a feature vector of a candidate word, then a semantic relevance between the word to be queried and the candidate word is calculated according to the feature vector of the word, and finally a query result is determined according to the semantic relevance.
There are many word embedding methods in the prior art, such as word2 vec-based word embedding method proposed by google, Transformer model proposed by google, and BERT model.
Although the word embedding methods in the prior art have greatly improved performance, the methods only consider the characteristics of the text and do not consider other characteristics attached to the text.
For example, in the context of spatial data applications, each spatial object contains not only textual description information but also location information. In some cases the semantics of the text may be affected by the spatial location of the text.
For example, when a user searches for "a garden" in a search system, and candidate results returned by the search system include two places far away from each other, namely "a garden" and "a stadium," the result "a garden" is closer to the search term "a park" from the text semantics, but the user may be near the a stadium when initiating a search, and the user really intends to find a way to the a stadium, and then the similarity between the search term and the candidate results is determined only according to the text semantics, so that the search results are biased.
As can be seen from the above example, in the context of spatial data application, text information needs to be combined with location information to obtain a correct query result.
In the prior art, text information and position information are processed separately when spatial data are processed, and accurate association cannot be established between the text information and the position information of the spatial data; the existing word vector coding model cannot show the association between words and position information, and even if a space position vector is added in a BERT model, the position information can be lost during model training, so that the model cannot obtain the implicit semantics of the space position; the existing word vector coding model is trained based on the text, only text information can be extracted for learning, and the influence of position information on words cannot be learned.
Disclosure of Invention
In order to solve the problems in the prior art, embodiments of the present invention provide a query method, a query device, an electronic device, and a storage medium.
In a first aspect, an embodiment of the present invention provides a query method, including:
determining a space area corresponding to a query request according to position information when the user initiates the query request;
searching a candidate query result set corresponding to the query request in the space region according to the text description information of the query request;
determining a feature vector of text description information of the query request and a feature vector of each candidate query result in the candidate query result set according to a preset mapping relation between words and word embedding vectors; the word embedding vector reflects the association degree between a word and other words in the text where the word is located and the association degree between the word and a space region; the feature vector is obtained according to the word embedding vector of the word contained in the text description information or the candidate query result;
and sorting and returning each candidate query result in the candidate query result set to the user according to the distance between the feature vector of each candidate query result in the candidate query result set and the feature vector of the text description information of the query request.
In the above technical solution, before the step of determining the spatial region corresponding to the query request according to the location information when the user initiates the query request, the method further includes:
acquiring sample space data, wherein the sample space data comprises position information and text description information;
generating corresponding word embedding vectors for each word in the text description information according to the position information and the text description information;
and establishing a mapping relation between the words and the corresponding word embedding vectors.
In the foregoing technical solution, the generating a corresponding word embedding vector for each word in the text description information according to the position information and the text description information specifically includes:
determining a space sub-region where a word is located for each word in the text description information in a quad-tree division mode by combining the position information; obtaining a space position coding vector and a space influence vector corresponding to each word according to a space subregion where each word in the text description information is located; wherein the spatial sub-region is a result of index space segmentation;
performing space fusion on each word in the text description information according to the space position coding vector and the space influence vector of each word in the text description information to obtain a space fusion vector containing association degrees of the words and different space subregions;
gathering the space sub-regions, and replacing words in the gathered space sub-regions with space fusion vectors of the words; calculating the space attention value of the word according to the space fusion backward quantity of the word in the gathered space subregion and the space influence vector of the word to obtain the space attention vector of the word; the spatial attention vector is used for highlighting the influence of the spatial position;
obtaining a corresponding word embedding vector according to the space attention vector of the word, the influence vector of the word and the region vector of the word; wherein the influence vector of the word is generated by the space attention vector of the word and the space influence vector of the word; the region vector of the word refers to a coding vector corresponding to a subspace region divided by the quadtree.
In the above technical solution, the performing spatial fusion on each word in the text description information according to the spatial position coding vector and the spatial influence vector of each word in the text description information to obtain a spatial fusion post-vector for reflecting the degree of association between one word and different spatial subregions specifically includes:
inputting the space position coding vector and the space influence vector of each word in the text description information into a word space fusion model to obtain a space fusion vector of each word in the text description information; wherein the content of the first and second substances,
the word space fusion model comprises a one-dimensional convolution layer and a feedforward neural network; wherein the content of the first and second substances,
the one-dimensional convolutional layer extracts effective characteristics in the space position coding vector through a convolutional kernel function, and eliminates a space sub-region with space influence lower than a preset threshold according to the space influence vector;
the feedforward neural network comprises an input layer, a hidden layer and an output layer, wherein only one hidden layer is arranged, and the output layer sets inverted quad-tree coding of a first word for the first word to be predicted by the input layer; and the objective function of the feedforward neural network is used for realizing the fusion judgment of the position information and the text description information.
In the above technical solution, the aggregating the spatial sub-regions and replacing words in the aggregated spatial sub-regions with the space-fused vectors of the words specifically includes:
gathering the space sub-regions through a convolution layer part of the space attention model, and replacing words in the gathered space sub-regions with space fusion vectors of the words; the convolutional layer part of the spatial attention model comprises a plurality of convolutional layers which are sequentially stacked, and the convolutional layers are used for realizing aggregation of spatial sub-regions and association between the aggregated spatial sub-regions and a word set;
correspondingly, the calculating the spatial attention value of the word according to the spatial fusion backward quantity of the word in the collected spatial subregion and the spatial influence vector of the word to obtain the spatial attention vector of the word specifically includes:
inputting the space attention layer part of the space attention model according to the space fusion backward vector of the words in the gathered space subarea, and calculating the space attention value of the word by combining the space attention layer part with the space influence vector of the word to obtain the space attention vector of the word; wherein the spatial attention layer part of the spatial attention model is stacked with a plurality of spatial attention layers for highlighting the influence of spatial position in the spatial fusion backward measure of the words in the post-aggregation spatial subregion.
In the above technical solution, the obtaining a corresponding word embedding vector according to the spatial attention vector of the word, the influence vector of the word, and the region vector of the word specifically includes:
taking the space attention vector of the word, the influence vector of the word and the area vector of the word as input data of a BERT model, training a Mask LM (Levenberg model) task on the BERT model, and after the training of the Mask LM task is finished, outputting a word space relevance vector for reflecting the relevance between the word and the space area by the BERT model;
setting a first label for a word in a preset space subregion set according to the word space relevance vector, then randomly selecting a word in the preset space subregion according to a preset proportion, replacing the selected word with a word outside the preset space subregion set, and setting a second label for the replaced word; randomly selecting two words in the preset space subregion, determining a CLS mark of a word vector according to a comparison result, and finally inputting the BERT model which outputs a word embedding vector; wherein the content of the first and second substances,
the preset space subregion set is a set of the preset space subregion and an adjacent space subregion thereof.
In the above technical solution, the determining, according to a preset mapping relationship between words and word embedding vectors, a feature vector of text description information of the query request and feature vectors of each candidate query result in the candidate query result set specifically includes:
performing word segmentation operation on the text description information of the query request, determining corresponding word embedding vectors for words in the text description information obtained by the word segmentation operation according to a preset mapping relation between the words and the word embedding vectors, and determining a feature vector of the text description information according to the word embedding vector of each word in the text description information;
performing word segmentation operation on each candidate query result in the candidate query result set, determining a corresponding word embedding vector for a word in each candidate query result obtained by the word segmentation operation according to a preset mapping relation between the word and the word embedding vector, and determining a feature vector of each candidate query result in the candidate query result set according to the word embedding vector of each word in each candidate query result.
In a second aspect, an embodiment of the present invention provides an inquiry apparatus, including:
the device comprises a space region determining module, a searching module and a searching module, wherein the space region determining module is used for determining a space region corresponding to a searching request according to position information when the user initiates the searching request;
a candidate query result set determining module, configured to search, according to the text description information of the query request, a candidate query result set corresponding to the query request in the spatial region;
a feature vector determination module, configured to determine a feature vector of text description information of the query request and feature vectors of each candidate query result in the candidate query result set according to a preset mapping relationship between a word and a word embedding vector; the word embedding vector reflects the association degree between a word and other words in the text where the word is located and the association degree between the word and a space region; the feature vector is obtained according to a word embedding vector of a word contained in the text description information or the candidate query result;
and the distance calculation and sorting module is used for sorting and returning each candidate query result in the candidate query result set to the user according to the distance between the feature vector of each candidate query result in the candidate query result set and the feature vector of the text description information of the query request.
In a third aspect, an embodiment of the present invention provides an electronic device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, where the processor executes the computer program to implement the steps of the query method according to the embodiment of the first aspect of the present invention.
In a fourth aspect, an embodiment of the present invention provides a non-transitory computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the steps of the query method according to the embodiment of the first aspect of the present invention.
When the query method, the query device, the electronic device and the storage medium provided by the embodiment of the invention are used for performing query operation, the candidate result set in the specific space region is searched according to the position information of the query request, and then the feature vector of the query request combined with the text information and the position information is compared with the feature vector of the candidate result set combined with the text information and the position information, so that the query result is determined in the candidate result set. Because the query is not carried out only according to the text information but the position information is added during the query, the query result is more accurate.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and those skilled in the art can also obtain other drawings according to the drawings without creative efforts.
FIG. 1 is a flowchart of a query method according to an embodiment of the present invention;
FIG. 2 is a diagram illustrating an embodiment of indexing sample space data using a quadtree;
fig. 3 is a schematic structural diagram of a word space fusion model involved in the query method according to the embodiment of the present invention;
FIG. 4 is a schematic diagram of a spatial attention model involved in a query method provided by an embodiment of the invention;
FIG. 5 is a flowchart of operations to be performed by the convolutional layer in the spatial attention model involved in the query method provided by the embodiment of the present invention;
fig. 6 is a schematic structural diagram of a spatial attention layer in a spatial attention model involved in a query method according to an embodiment of the present invention;
fig. 7 is a schematic diagram illustrating word vector merging performed by a spatial attention layer in a spatial attention model involved in a query method according to an embodiment of the present invention;
FIG. 8 is a flowchart of operations to be performed by a spatial attention layer in a spatial attention model involved in a query method according to an embodiment of the present invention;
fig. 9 is a schematic structural diagram of a BERT model used in the query method according to the embodiment of the present invention;
fig. 10 is a schematic diagram of input data of a BERT model input layer used in the query method according to the embodiment of the present invention;
fig. 11 is a flowchart of weakening the spatial relevance of an irrelevant word by a spatial text prediction task in a BERT model in the query method according to the embodiment of the present invention;
FIG. 12 is a diagram of an inquiry apparatus according to an embodiment of the present invention;
fig. 13 is an entity structure diagram of an electronic device related to a query method according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be obtained by a person skilled in the art without any inventive step based on the embodiments of the present invention, are within the scope of the present invention.
Fig. 1 is a flowchart of a query method according to an embodiment of the present invention, and as shown in fig. 1, the query method according to the embodiment of the present invention includes:
step 101, determining a spatial region corresponding to a query request according to position information when the user initiates the query request.
In the embodiment of the invention, when the user initiates the query request, the position of the user is the position information when the user initiates the query request. The location information may be latitude and longitude coordinate information. The position information can be obtained through a terminal device with a positioning function of a user, such as a mobile intelligent terminal device, including an intelligent mobile phone, an intelligent watch, a tablet computer, a notebook computer and the like. The terminal device of the user obtains the position information of the user when initiating the query request through a satellite positioning module such as a GPS positioning module, a Beidou positioning module and the like.
In the embodiment of the present invention, when a user initiates a query request, query content input by the user is called text description information. "A park" as entered by the user in the search box is the textual description of the query request.
In the query operation related to the location information, the query result desired by the user is generally the query result adjacent to the location where the user is currently located. For example, if a user queries "people park", hundreds or thousands of "people parks" around the country, and if the user does not add a specific qualifier, such as "shanghai people park", before the keyword "people park", then the "people park" that the user living in joy generally wishes to find is the closest people park to him, such as "joy people park". Therefore, in this step, the spatial region to which the user belongs is determined according to the location information when the user initiates the query request.
The division of the space region may be preset, for example, the space region is divided according to a quadtree division manner, and in the embodiment of the present invention, the method for dividing the space region is not limited.
The spatial regions have identifiers that distinguish one spatial region from another, such as uniquely identifying one spatial region with a number. The identifier may also adopt other types of representation manners, such as combining a place name with a number, using a zip code as an identifier of a space region, and the like, and the representation manner of the space region is not limited in the embodiment of the present invention.
And comparing the position information of the query request with the space region division result according to the set space region division result, and determining the space region corresponding to the query request. For example, the corresponding space area is searched according to the longitude and latitude coordinate information.
Step 102, according to the text description information of the query request, searching a candidate query result set corresponding to the query request in the space region.
In the previous step, the spatial region to which the query request belongs is already determined according to the position information in the query request, and in the present step, in the spatial region corresponding to the query request, a candidate query result set corresponding to the query request is searched according to the words contained in the text description information of the query request.
Specifically, the words contained in the text description information can be used as keywords, and candidate query results can be searched in a specific spatial region in a fuzzy matching mode. Since there are typically multiple candidate query results, a set of candidate query results may be generated.
For example, if a user initiates an inquiry request for searching for "people park" in jiaxing city, the inquiry request corresponds to a spatial region of jiaxing city, and the candidate inquiry result corresponding to the inquiry request is a result related to "people park" in jiaxing city region, but not a result related to "people park" in Shanghai city or metropolitan area.
The candidate query result is spatial data, which not only includes text description information, but also includes location information. If a candidate includes not only the textual description of "people park" but also latitude and longitude coordinate information of the park.
Step 103, determining a feature vector of the text description information of the query request and a feature vector of each candidate query result in the candidate query result set according to a preset mapping relation between words and word embedding vectors.
In the embodiment of the invention, the word embedding vector reflects the association degree between the word and other words in the text where the word is located and the association degree between the word and the space region; the feature vector is obtained from a word embedding vector of a word included in the text description information or the candidate query result.
In the embodiment of the present invention, the mapping relationship between the words and the word embedding vectors may be represented as follows: { word, word embedding vector }. According to the mapping relation between the words and the word embedding vectors, corresponding word embedding vectors can be found for word searching.
The mapping relationship between the word and the word embedding vector can be stored in a database, such as a Redis database, in which the word is used as a Key Value and the word embedding vector is used as a Value.
In the embodiment of the present invention, the mapping relationship between the words and the word embedding vectors is generated in advance based on the sample space data, and in other embodiments of the present invention, a detailed description will be given of how to generate the mapping relationship between the words and the word embedding vectors from the sample space data.
The implementation process of the step specifically comprises the following steps:
performing word segmentation operation on the text description information of the query request, determining corresponding word embedding vectors for words in the text description information obtained by the word segmentation operation according to a preset mapping relation between the words and the word embedding vectors, and determining a feature vector of the text description information according to the word embedding vector of each word in the text description information;
performing word segmentation operation on each candidate query result in the candidate query result set, determining a corresponding word embedding vector for a word in each candidate query result obtained by the word segmentation operation according to a preset mapping relation between the word and the word embedding vector, and determining a feature vector of each candidate query result in the candidate query result set according to the word embedding vector of each word in each candidate query result.
In the implementation process, the word segmentation operation is common knowledge of persons skilled in the art, and in the embodiment of the present invention, implementation details of the word segmentation operation are not further described.
After the word vectors of all words in the text description information of the query request or the candidate query result are obtained, the feature vectors of the whole text description information or the candidate query result can be further obtained from the word vectors of the single word. For example, a weighted average calculation is performed on word vectors of all words included in the text description information or the candidate query result, so as to obtain a feature vector of the whole text description information or the candidate query result. Other calculation methods may also be used to calculate the feature vector of the entire text description information or the candidate query result, which is not limited in the embodiment of the present invention.
And step 104, sorting and returning each candidate query result in the candidate query result set to the user according to the distance between the feature vector of each candidate query result in the candidate query result set and the feature vector of the text description information of the query request.
In the embodiment of the invention, a cosine distance calculation method can be adopted when the distance value is calculated. Assuming that Vq is a feature vector of text description information of a query request and Vr is a feature vector of a certain candidate result, a calculation formula of cosine distance is as follows:
D=cos_sine(Vq,Vr);
where cos _ sine is the cosine distance calculation function.
After the distance value is obtained through calculation, the candidate results are sorted in a reverse order, the candidate results which are sorted in the front order are more closely related to the query request of the user, the probability that the query results are needed by the user is higher, and the sorted candidate results can be output to the user for the user to select.
When the query operation is performed, the query method provided by the embodiment of the invention searches the candidate result set in the specific spatial region according to the position information of the query request, and then compares the feature vector of the query request, which combines the text information and the position information, with the feature vector of the candidate result set, which combines the text information and the position information, so as to determine the query result in the candidate result set. Because the query is not carried out only according to the text information but the position information is added during the query, the query result is more accurate.
Based on any one of the above embodiments, in an embodiment of the present invention, before step 101, the method further includes:
acquiring sample space data, wherein the sample space data comprises position information and text description information;
generating corresponding word embedding vectors for each word in the text description information according to the position information and the text description information;
and establishing a mapping relation between the words and the corresponding word embedding vectors.
In the previous embodiment of the present invention, the mapping relationship between the words and the word embedding vectors is preset, and in the embodiment of the present invention, the mapping relationship between the words and the word embedding vectors is generated according to the sample space data.
The sample space data is space data as a sample, and the space data is data including position information, and the space data generally includes text description information and position information. The text description information mainly relates to the content of the text, and four words such as 'people park' belong to the text description information. Location information, as the name implies, is used to represent spatial location, typically in the form of latitude and longitude coordinate data. If the longitude and latitude coordinates of the 'people park' are 'east longitude 121.473221 and north latitude 31.232229', the coordinate value is the position information of the 'people park'.
As can be seen from the above illustration, the place names in the map are typical spatial data.
The format of the spatial Data may be Data ═ p, t >, where p is location information of the spatial Data and t is text description information of the spatial Data.
After a certain amount of sample space data is obtained, generating corresponding word embedding vectors for each word in the text description information according to the position information of the sample space data and the text description information. Specifically, the method comprises the following steps:
step S1, determining a space sub-region where a word is located for each word in the text description information in a quadtree division mode by combining the position information; obtaining a space position coding vector and a space influence vector corresponding to each word according to the space subregion where each word in the text description information is located; wherein the spatial sub-region is a result of index space segmentation;
step S2, according to the space position coding vector and the space influence vector of each word in the text description information, carrying out space fusion on each word in the text description information to obtain a space fusion vector containing the association degree of the word and different space sub-regions;
step S3, gathering the space sub-regions, and replacing words in the gathered space sub-regions with space fusion vectors of the words; calculating the space attention value of the word according to the space fused vector of the word in the gathered space subregion and the space influence vector of the word to obtain the space attention vector of the word; the spatial attention vector is used for highlighting the influence of the spatial position;
step S4, obtaining a corresponding word embedding vector according to the space attention vector of the word, the influence vector of the word and the region vector of the word; wherein the influence vector of the word is generated by the space attention vector of the word and the space influence vector of the word; the region vector of the word refers to a coding vector corresponding to a subspace region divided by the quadtree.
According to the query method provided by the embodiment of the invention, according to the position information and the text description information contained in the sample space data, a plurality of operations such as space position coding, space influence coding, word fusion, attention calculation and the like are carried out on the words in the text description information, so that word embedding vectors corresponding to the words are obtained, the mapping relation between the words and the word embedding vectors is generated, and a good foundation is laid for the subsequent query operation.
Based on any one of the above embodiments, in the embodiment of the present invention, the step S1 specifically includes:
firstly, word segmentation operation is carried out on text description information in spatial data to obtain each word contained in the text description information.
And then, coding the words according to the incidence relation between the words and the position information of the spatial data to obtain a spatial position coding vector.
The purpose of encoding the words is to establish an association between the words of the sample space data and the position information. In the embodiment of the invention, the space position coding vector of the word is constructed based on the coding mode of the space text index.
Specifically, the sample space data is first indexed using a quadtree, which divides the index space into different subspaces. FIG. 2 is a diagram illustrating an example implementation of a quadtree index into sample space data. In this embodiment, the index space is divided into 10 sub-regions by using a quadtree according to the distribution characteristics of the sample space data, so that the sample space data in each sub-region contains a keyword set. As shown in fig. 2, the resulting 10 sub-regions are numbered 0, 4, 5, 6, 7, 8, 9, 10, 11, 12 respectively (in fig. 2 there are no numbers 1, 2 and 3 because, according to the rule of Z-order ordering, if sub-region number 0 is divided into 4, the corresponding sub-region is numbered 0,1, 2, 3).
The set of words contained in the sub-regions within a smaller range can be obtained from the set of keywords contained in the sample space data within one sub-region. A vector representation is set based on the spatial region coding method, and is referred to as a spatial position coding vector in the embodiment of the present invention because the vector can describe the association between the words of the sample spatial data and the position information.
Specifically, when encoding is performed, the values in each spatial position encoding vector are sorted from low to high according to the Z-order number of the spatial region, and if the sub-region contains a corresponding word, 1 is filled, and if the sub-region does not contain the word, 0 is filled. For example, in the sub-region distribution diagram shown in fig. 2, assuming that only sub-regions 0, 9, 12 contain the word "meal-shop", the vector for the word "restaurant" is represented as:
BVec<restaurant>=<1,0,0,0,0,0,0,0,0,1,0,0,1>;
The vector is 13-dimensional and corresponds to sub-regions numbered from 0 to 12, and although the sub-regions numbered 1, 2, and 3 are not divided in the embodiment shown in fig. 2, the vector includes dimensions corresponding to the sub-regions numbered 1, 2, and 3 for the convenience of vector representation and calculation.
The space position coding vector of the word constructed by the coding mode based on the space text index can describe whether one space subregion comprises a certain word, so that simple association of the word and the position information can be established, visual mapping from the text information to the position information is realized, and the text and the position information are reserved.
And coding all the words according to the coding mode, combining the coding results into a matrix of Base _ Word, wherein each line of the matrix is a space position coding vector of one Word, and the number of lines of the matrix depends on the number of the words contained in the text description information of the space data.
Finally, according to the distribution of the spatial data in each sub-area, the influence of the words in the spatial data in each sub-area of the space can be calculated.
The influence can be expressed by an influence factor, and the calculation formula of the influence factor is as follows:
Ce=Numword/Numall
wherein, NumwordRepresenting the amount of spatial data containing a word in a sub-region, and NumallRepresenting the amount of all spatial data in a sub-region.
Based on the influence factor, a spatial influence vector of the word may further be derived. A word corresponds to a spatial influence vector, the columns of which correspond to the sub-regions where the word is located, and the columns store the influence factors of the word on the sub-regions to which the columns correspond.
The spatial influence vectors of a plurality of words may form a spatial influence matrix Ce _ Word, the rows of which correspond to a Word and the columns of which correspond to the sub-areas where the Word is located, and for the columns of which corresponding to the sub-areas containing a Word, the influence factor of the Word on the sub-areas is stored.
As can be seen from the calculation formula of the influence factor, the larger the number of words contained in a certain sub-region is, the larger the influence of the word on the sub-region is.
For example, in the influence matrix Ce _ Word, the data for the row corresponding to the Word "restaurant" may have the form:
Ce_Word[i]=<0.121,0,0,0,0,0,0,0,0,0.456,0,0,0.238>
other words in the sample space data may also have similar forms.
The query method provided by the embodiment of the invention realizes the generation of the space position coding vector and the space influence force vector of the word.
Based on any one of the above embodiments, in the embodiment of the present invention, the step S2 specifically includes:
and inputting the space position coding vector and the space influence vector of each word in the text description information into a word space fusion model to obtain a space fusion vector of each word in the text description information.
In the previous step, spatial position-coding vectors are generated for words in the spatial data. The spatial position coded vector can describe whether a spatial sub-region comprises a certain word, and simple association of the word and the spatial position is established. In order to further understand the degree of association between the spatial sub-region and the word, in the embodiment of the present invention, a word space fusion model (ws2 vec: word spatial to vector) is used to learn the association relationship of the word in the spatial position.
Fig. 3 is a schematic structural diagram of a word space fusion model, and as shown in fig. 3, the word space fusion model may be divided into two parts, where the first part is a one-dimensional convolution layer, and the second part is a feedforward neural network similar to a word2vec model and including only an input layer, a hidden layer, and an output layer.
The function of the one-dimensional convolution layer is to extract effective features in the space position coding vector through convolution kernel functions, and establish the association of the same word in different areas through convolution operation.
Specifically, the expression of the convolution kernel is as follows:
core(xi)=f(xi-j,…,xi-1,xi,xi+1,…,xi+j)g(Ce_Word[word,i],2j+1);
wherein i is a column coordinate in a space position coding vector of the word, namely a sub-region code corresponding to the word, j is a convolution kernel length coefficient, and the length of the one-dimensional convolution is 2j +1 as can be seen from the above formula; the function f () is a convolution kernel calculation function, xiAre encoded values that participate in the convolution operation.
The significant features in the spatial position code vector extracted by the convolution kernel can be represented by WiAnd (4) showing.
In the embodiment of the invention, the values of the columns of a plurality of space position coding vectors can be considered together by adopting one-dimensional convolution, so that the relation of the same word on different sub-regions is established, wherein the value of j can be selected according to the actual situation.
The one-dimensional convolution layer can also eliminate sub-regions with too low influence, namely, filtering operation is carried out. Specifically, the influence distribution of a word in each spatial subregion is obtained from the spatial influence matrix of the word, the value of the influence distribution is vector-multiplied by the code value participating in the convolution operation, and an influence threshold θ is set. And eliminating the areas with too low influence, namely setting the value of the column of the space word vector with the value less than theta to be 0, so as to eliminate noise and eliminate the influence of the space subarea with low influence on the word space position association. The corresponding calculation formula is:
Ce_Word[word,i]xi>θ;
wherein word represents a word; i is the column coordinate in the spatial position encoding vector of the word; x is the number ofiIs the encoded value that participates in the convolution operation.
By the above filtering operation, the effective feature W in the vector is encoded by the spatial positioniObtaining an input word vector X for a feedforward neural networki
In the word space fusion model related to the embodiment of the invention, the feedforward neural network comprises an input layer, a hidden layer and an output layer; wherein, the hidden layer is only one.
Specifically, text description information of the spatial data is represented as a set of spatial position coding vectors of words according to vectors output by the one-dimensional convolutional layer, one word is randomly removed to serve as label data, and the rest vectors are input into a feedforward neural network for training.
For example, through the processing of the one-dimensional convolution layer, the space position coding vectors of a plurality of words of 'central restaurant, meal, very good food' are obtained; then the word of 'meal' is randomly removed, the Z-order code of the word of 'meal' is used as the output result of a feedforward neural network, the space position code vectors of other residual words are input into the network for learning, and the word of 'meal' is predicted by using other residual words. Through the training process, the association between the word 'meal' and other input words can be learned, including the association of text and the association of spatial position.
In order to be able to establish a close association of words and spatial positions, the output layer of the word-space fusion model is adapted compared to the existing word2vec model. The output layer will not use the huffman tree coding of the word2vec model, but use the coding based on the spatial inverted index to establish a spatial index for each word, and the index only contains the Z-order codes of the leaf nodes.
For example, in the example of the word "restaurant" described in the foregoing embodiment, the spatial index created for the word based on the coding of the spatial inverted index is represented by:
RVec<restaurant>=<0,9,12>。
Through the training of a feedforward neural network, the relation between words and spatial positions and the relation between the same word and different spatial positions are established, and according to the thought of word2vec, the weight matrix of the hidden layer is the solved result.
In order to learn the information of the spatial position when training the feedforward neural network, the objective function and the optimization function of word2vec are improved as follows. Firstly, an objective function δ of the feedforward neural network is set as:
Figure BDA0002717816400000161
where w is the word sought, which belongs to the set of words t, i is the encoding index of the spatial inverted index, lwA value of 1 subtracted from the length of the spatial inverse index code; σ in the formula is a maximum likelihood function for output layer spatial coding, which is of the form:
Figure BDA0002717816400000162
as shown in the above formula, the idea of word2vec maximum likelihood function is adopted to calculate di wExpressed as Z-order codes corresponding to each single word, in order to describe spatial characteristics and prevent negative values, the scheme uses a sigmod function to map the Z-order code values into [0,1 ]]Thereby preserving the spatial position diversity;
Figure BDA0002717816400000164
the result is the output result of the middle hidden layer and is also the object to be optimized;
Figure BDA0002717816400000163
the coded subvector representing the word w, i.e.<0>,<0,9>,<0,9,12>(ii) a With these parameters, the value of the maximum likelihood function can be calculated.
The tau function in the objective function is used for calculating the ratio of the size of the area corresponding to the word to the size of the total area, and is used as a weight parameter for adjusting the maximum likelihood function value, if the ratio is larger, the influence of the area of the word is larger, further optimization is needed more, and an accurate result is obtained, and the calculation formula is as follows:
Figure BDA0002717816400000171
wherein
Figure BDA0002717816400000172
Is the area of the i region to which the word w belongs, and
Figure BDA0002717816400000173
is the sum of all areas that contain the word w.
The description of the objective function calculation formula shows that the objective function combines the characteristics of the maximum likelihood function and the Z-order code, and the fusion judgment of the position information and the text description information is realized.
After the target function exists, the target function is enabled to reach the maximum value by adjusting the parameter weight of the hidden layer node only by using a random gradient ascending method, and when the target function reaches the maximum value, the weight of the middle hidden layer in the word space fusion model is the required vector after the word space fusion. In the embodiment of the present invention, the vector obtained based on the word space fusion model is also referred to as a space fused vector.
The following will further explain how to establish an accurate relationship between words and position information in spatial data by combining the word space fusion model provided by the embodiment of the present invention.
And step S21, performing convolution operation on the space position coding vector corresponding to the word by using the one-dimensional convolution layer in the word space fusion model, thereby extracting effective characteristics in the space position coding vector corresponding to the word and establishing the association of the same word in different space sub-regions.
As an alternative implementation manner, in step S21, a filtering operation is further performed on the result of the convolution operation to remove noise and remove the influence of the spatial subregion with low influence on the word spatial position association.
And step S22, constructing a label of the feedforward neural network according to the space position coding vector corresponding to the word, namely generating the reverse quad-tree coding of each word.
And step S23, initializing the feedforward neural network in the word space fusion model, including initializing a weight matrix of each layer node in the feedforward neural network, and setting the inverted quadtree code of the word at the corresponding output layer position according to the word predicted by the input layer of the feedforward neural network.
Step S24, training the feedforward neural network, and optimizing the weight parameters using the objective function described above.
In this step, the output result of step S21 is used as training data of the feedforward neural network.
And step S25, when the target function reaches the maximum value, finishing training, and outputting the weight matrix of the middle hidden layer of the feedforward neural network as a vector after word space fusion.
The query method provided by the embodiment of the invention realizes the accurate association between the words and the spatial positions in the spatial data through the word space fusion model.
Based on any one of the above embodiments, in the embodiment of the present invention, the step S3 specifically includes:
gathering the space sub-regions through a convolution layer part of the space attention model, and replacing words in the gathered space sub-regions with space fusion vectors of the words; the convolutional layer part of the spatial attention model comprises a plurality of convolutional layers which are sequentially stacked, and the convolutional layers are used for realizing aggregation of spatial sub-regions and association between the aggregated spatial sub-regions and a word set;
inputting the space attention layer part of the space attention model according to the space fusion backward vector of the words in the gathered space subarea, and calculating the space attention value of the word by combining the space attention layer part with the space influence vector of the word to obtain the space attention vector of the word; wherein the spatial attention layer part of the spatial attention model is stacked with a plurality of spatial attention layers for highlighting the influence of spatial position in the spatial fusion backward measure of the words in the post-aggregation spatial subregion.
In the previous step S2, the word space fusion model achieves an accurate association between words and spatial positions in the spatial data. In order to focus on the influence of the position information on the vector corresponding to the word, in the embodiment of the present invention, a Spatial-Attention (Spatial-Attention) model is adopted.
Fig. 4 is a schematic diagram of a spatial attention model, and as shown in fig. 4, the spatial attention model includes two parts, the first part is a convolution layer, and the second part is a spatial attention layer.
The convolution layer part of the spatial attention model comprises a plurality of convolution layers which are stacked in sequence. The convolutional layer part is mainly used for constructing the training input data of the spatial attention layer. Specifically, a convolution kernel function is used in the convolution layer to aggregate a plurality of regions, a text set after the aggregation regions is extracted, and the text set is used as the input of the spatial attention layer.
The convolutional layer is selected from the spatial attention model because the convolutional layer can maximally correlate different spatial sub-regions, and the spatial correlation of words is not omitted. Taking fig. 2 as an example, the adjacent sub-regions of the sub-region 10 in fig. 2 include the sub-region 8, the sub-region 9 and the sub-region 11, and the adjacent sub-regions of the sub-region 9 are the sub-region 0, the sub-region 8, the sub-region 10, the sub-region 11, the sub-region 12 and the sub-region 6, and the relationship from the sub-region 8 to the sub-region 10, the sub-region 9 and the sub-region 11 can only be established through the sub-region 10, but the relationship from the sub-region 8 to the sub-region 0, the sub-.
The convolution layer portion uses multiple layers of convolution stacks to extend the range of sub-region association. The convolution is in continuous dimensionality reduction, a certain range of area can be contained through convolution operation of one convolution layer, and a wider area can be contained by operating the convolution operation on a subsequent convolution layer, so that a wider association is established, and a space attention layer can identify more accurate word space association during operation.
FIG. 5 is a flow chart of operations to be performed by the convolutional layer in the spatial attention model, as shown in FIG. 5, including:
and step S31, taking the space region and the sample space data after the quadtree division as the input of the convolution layer, and setting a convolution kernel function according to the space region after the quadtree division.
Since the quadtree division is often irregular, a window of convolution kernels is formed by including up to 8 adjacent subregions around each subregion, regardless of size, centered on each subregion. For example, if the center is sub-region 0 in fig. 2, the kernel function window includes several sub-regions numbered 0, 4, 6, 8, 9, and 12.
Step S32, preprocessing the spatial data, wherein the preprocessing comprises: and extracting words of the sample space data in each sub-region, and constructing a word set in the sub-region according to the words.
And step S33, scanning the space sub-regions divided by the quadtree line by line according to the sequence from left to right, and performing convolution operation by using the convolution kernel function set in the step S31 in the scanning process to obtain the aggregated space sub-regions.
Unlike the general convolution calculation method, the convolution operation in this step calculates Z-order coding of the spatial sub-region, and maps at most nine sub-regions (currently scanned sub-region and at most 8 adjacent sub-regions around) to a new spatial sub-region through convolution operation, and the new spatial sub-region is the aggregated spatial sub-region.
And step S34, constructing a word set of the gathered space sub-regions according to the convolution operation result.
According to the window of the convolution kernel function set in step S31, words of the spatial data of all spatial sub-regions in the window can be extracted, and these words are combined into a word set, and the word set of the clustered sub-regions is obtained by associating the word set with the clustered sub-regions calculated in step S33.
Step S35, the clustered spatial sub-regions and the word sets with the clustered spatial sub-regions are used as the input of the next convolutional layer or the input of the output layer.
Since there are multiple convolutional layers, if there is a convolutional layer after the current convolutional layer, the word set of the aggregated sub-region and the aggregated sub-region generated by the current convolutional layer can be used as the input of the next convolutional layer, and if the current convolutional layer is the last convolutional layer, the word set of the aggregated sub-region and the aggregated sub-region generated by the current convolutional layer can be used as the input of the output layer.
Step S36, determine whether the operation of the convolutional layer is finished, if not, execute step S32 to calculate the next convolutional layer, otherwise execute step S37.
In this step, whether or not the operation of the convolution layer is completed can be determined based on the number of preset convolution layers.
Step S37, all words in the word set corresponding to the current Spatial sub-region are converted into the space-fused vectors generated by the word space fusion model, and then a matrix related to the current Spatial sub-region is output, and the set of space-fused vectors corresponding to each current Spatial sub-region in the matrix is input to a Spatial-Attention (Spatial-Attention) layer as a whole text.
In the previous step, the aggregation of the spatial sub-regions is achieved by convolutional layers. In this step, the current spatial sub-region is a spatial sub-region that has undergone aggregation several times, and the word set of the current spatial sub-region is a set constructed by words in the aggregated spatial sub-region.
All words in the word set corresponding to the current space subregion are replaced by space fusion vectors corresponding to the words generated by the previous word space fusion model, so that the vectors can form an input matrix AmAnd m is the code of the corresponding sub-region.
The space fusion backward vector set corresponding to the current space sub-region is input into the space attention layer as a whole text, so that the maximum realization can be realized
The spatial position of the words is correlated.
The spatial attention layer part of the spatial attention model is stacked with a plurality of spatial attention layers, and the spatial attention layers are used for highlighting the influence of spatial positions in word vectors corresponding to words, so that more accurate word vectors fusing position information are coded.
Fig. 6 is a schematic structural diagram of a spatial attention layer, and as shown in fig. 6, the spatial attention layer is different from the conventional attention layer in the prior art mainly in two points: first, the input of the spatial Attention layer is no longer a sentence or a segment, but a set of word vectors corresponding to words calculated in the convolutional layer part is used as the raw material for the Attention calculation, in which A1 mI.e. representing a spatial area amThe first row of the corresponding matrix, i.e. the vector of the first word, may do so taking into account the relevance of the words in a certain spatial range. Second, a spatial influence matrix is introduced in the calculation of the Attention (Attention) value, enabling the Attention of the position information in the calculation of the Attention value. Wherein, the calculation formula of the attention value is as follows:
Figure BDA0002717816400000211
wherein, in the previous parenthesis of the formula
Figure BDA0002717816400000212
Is the attention calculation method in the prior art, and the latter bracket of the formula
Figure BDA0002717816400000213
The method is a weight parameter constructed by using a word space influence moment array, wherein word refers to a word corresponding to a current node, namely, word is a word input by the node, and i is a vector subscript.
From the above equation, it can be seen that the weight coefficient is larger as the spatial influence is larger, the weight coefficient is smaller as the spatial influence is smaller, and the spatial influence coefficient is the smallest when the spatial influence coefficient is 0, and therefore, the value of the Attention weight having the spatial influence, that is, α can be amplified by this operationiWhile narrowing the value of the Attention weight without spatial influence, thereby achieving the purpose of position informationAttention is paid.
Because different sub-regions may have the same word, after the text data of each sub-region is completely operated, word vectors of the same word need to be added and combined to obtain a final result; fig. 7 is a schematic diagram of word vector merging performed by a Spatial Attention layer in a Spatial Attention model according to the query method provided in the embodiment of the present invention, and as shown in fig. 7, each Spatial-Attention layer performs Attention calculation for each Spatial sub-region, and finally summarizes calculation results to the word vector merging layer, and after summing up vectors of the same word to obtain a result, performs the same operation on the input of the next Spatial-Attention layer, and repeats until all Spatial Attention layers are calculated.
FIG. 8 is a flowchart of operations to be performed by the spatial attention layer in the spatial attention model, as shown in FIG. 8, the operations to be performed by the spatial attention layer include:
step S301, receiving the output result of the convolutional layer, initializing a spatial attention layer, initializing three weight matrixes q, k and v, and loading a spatial influence matrix.
Step S302, performing data formatting processing, which mainly includes: and extracting the word vectors of the words corresponding to the spatial sub-regions as the input of the spatial attention layer.
And step S303, performing spatial attention calculation on the words one by one, calculating corresponding attention values, and forming output word vectors.
In this step, the spatial attention calculation for the word may be performed by referring to the aforementioned attention calculation formula.
And S304, summarizing the calculation results of each sub-area, adding and summing the vectors of the same word, and outputting the sum as the calculation result of the current space attention layer.
Step S305, judging whether all the spatial attention layers are calculated, if so, turning to step S306, otherwise, taking the output of the layer as the input of the next spatial attention layer, and executing step S302 again.
In this step, whether the calculation of the spatial attention layer is finished or not may be determined according to a preset number of spatial attention layers.
And S306, outputting the calculated word vector, wherein the influence of the effective space position is amplified by the word vector through space attention operation.
In the embodiment of the present invention, the word vector finally output by the spatial attention model is referred to as a spatial attention vector.
The query method provided by the embodiment of the invention amplifies the influence of the position information in the space attention vector of the word through the attention mechanism.
Based on any one of the above embodiments, in the embodiment of the present invention, the step S4 specifically includes:
taking the space attention vector of the word, the influence vector of the word and the area vector of the word as input data of a BERT model, training a Mask LM (Levenberg model) task on the BERT model, and after the training of the Mask LM task is finished, outputting a word space relevance vector for reflecting the relevance between the word and the space area by the BERT model;
setting a first label for a word in a preset space subregion set according to the word space relevance vector, then randomly selecting a word in the preset space subregion according to a preset proportion, replacing the selected word with a word outside the preset space subregion set, and setting a second label for the replaced word; randomly selecting two words in the preset space subregion, determining a CLS mark of a word vector according to a comparison result, and finally inputting the BERT model which outputs a word embedding vector; wherein the content of the first and second substances,
the preset space subregion set is a set of the preset space subregion and an adjacent space subregion thereof.
After the spatial attention operation is completed, in the embodiment of the present invention, a BERT (bidirectional Encoder representation from transforms) pre-training model is used to encode word vectors, and through a bidirectional Transformer connection mechanism of the BERT, association between words and spatial positions can be more comprehensively established, because the BERT model can read complete context information of the whole text during training.
Fig. 9 is a schematic structural diagram of the BERT model used in the embodiment of the present invention, and as shown in fig. 9, the BERT model is divided into 3 parts, i.e., an input layer, a transform coding layer, and an output layer.
The BERT model in the prior art is trained only for text, so the input data of the input layer is formed by adding word vectors, position vectors of words, and label vectors of texts to which the words belong. In the embodiment of the present invention, the BERT model needs to learn the implicit semantics of the position information, so the input data of the input layer of the BERT model includes word vectors, influence vectors of words, and region vectors of words. Fig. 10 is a diagram illustrating input data of the BERT model input layer. The term vector refers to a vector including Spatial-position related information output by a Spatial-Attention (Spatial-Attention) model, i.e., the aforementioned Spatial Attention vector. E in word vector[cls]And E[seq]Respectively represent the beginning and the end marks of the phrase sequence, i.e. the words between the two marks belong to the same sentence. The influence vector of a word refers to a vector capable of distinguishing the spatial influence sensitivity level of a word, which can be generated from the spatial attention vector of a word and the spatial influence vector of a word. The term region vector refers to the coding vector corresponding to the subspace region divided by the quadtree, for example, the term region vector EARepresenting the code vectors of the subspace region A after the quad-tree division.
In the embodiment of the present invention, the region vector is used to replace the tag vector of the text to which the word belongs, because the relevance of the same word in different regions needs to be considered.
In calculating the influence vector of a word, a spatial attention vector E is usediMultiplying the calculation mode of the self inner product of the space influence force vector corresponding to the word, so that the sensitive and non-sensitive words of the space influence force can be effectively distinguished, and the calculation formula is as follows:
Figure BDA0002717816400000231
where Ce _ Word [ Word ] represents the row vector of the current Word in the matrix Ce _ Word.
After the input of the BERT model is improved, the BERT model is used for training a Mask LM basic task, the relevance of words is obtained through the training of the BERT model, and because the input word vectors are coded through the space attention model and already contain the relevance information of space positions, the codes output by the Mask LM task are already coding vectors for learning the relevance between the words and the space. In the embodiment of the invention, the vector generated by the BERT model is called a word space association degree vector.
However, the Mask LM task may have semantic over-interpretation, and learns a word with small Spatial relevance as a word with strong Spatial relevance, and to this problem, the embodiment of the present invention weakens the Spatial relevance of an irrelevant word by a Spatial Text Prediction (BERT) training task oriented to a Spatial position. FIG. 11 is a flow chart for attenuating irrelevant word spatial relevance through the spatial text prediction task in the BERT model, as shown in FIG. 11, comprising the steps of:
and step S41, taking the word space relevance vector generated by the BERT model as input, scanning the sub-space regions divided by the quadtree line by line, taking each sub-space region as a center, and selecting at most 8 adjacent sub-regions as basic units for task calculation.
The operation of this step is similar to that performed by the convolutional layer in the spatial attention model, and therefore, will not be repeated here.
And step S42, labeling all words in each sub-area in the selected area, which indicates that the words belong to the same area.
And step S43, randomly selecting words in a certain proportion from the word set corresponding to the sub-region for replacement, replacing the words with words in the sub-region set with a longer distance, and labeling to indicate that the words and the original words in the sub-region do not belong to the same sub-region.
In the embodiment of the present invention, the ratio of the randomly selected word may be 30%, and in other embodiments of the present invention, other ratio values may also be used.
And step S44, randomly combining every two words in the same sub-region, filling 0 in the CLS mark of the word vector if the two selected words are from the sub-region, otherwise filling 1 in the CLS mark, and inputting the CLS mark into a BERT model for coding.
In this step, it is considered that the relevance of the words in the spatial sub-region far away from each other should be low, so the words in the spatial sub-region far away from each other are marked as not related to the word in the current sub-region, that is, the feature of far away spatial position is used to reduce the word spatial relevance and reduce the probability of occurrence of the spatial relevance which is calculated excessively.
The word vector output by the step S45 and the BERT model is the required word embedding vector.
The query method provided by the embodiment of the invention realizes the generation of the word embedding vector through the BERT model.
Based on any of the above embodiments, fig. 12 is a schematic diagram of an inquiry apparatus provided in an embodiment of the present invention, and as shown in fig. 12, the inquiry apparatus provided in an embodiment of the present invention includes:
a spatial region determining module 1201, configured to determine a spatial region corresponding to a query request according to location information when the query request is initiated by a user;
a candidate query result set determining module 1202, configured to search, according to text description information of the query request, a candidate query result set corresponding to the query request in the spatial region;
a feature vector determining module 1203, configured to determine, according to a preset mapping relationship between a word and a word embedding vector, a feature vector of text description information of the query request and feature vectors of each candidate query result in the candidate query result set; the word embedding vector reflects the association degree between a word and other words in the text where the word is located and the association degree between the word and a space region; the feature vector is obtained according to a word embedding vector of a word contained in the text description information or the candidate query result;
a distance calculating and sorting module 1204, configured to sort and return to the user each candidate query result in the candidate query result set according to a distance between a feature vector of each candidate query result in the candidate query result set and a feature vector of the text description information of the query request.
When the query device provided by the embodiment of the invention performs query operation, the candidate result set in the specific spatial region is searched according to the position information of the query request, and then the feature vector of the query request, which combines the text information and the position information, is compared with the feature vector of the candidate result set, which combines the text information and the position information, so that the query result is determined in the candidate result set. Because the query is not carried out only according to the text information but the position information is added during the query, the query result is more accurate.
Fig. 13 is an entity structure schematic diagram of an electronic device related to a query method provided in an embodiment of the present invention, and as shown in fig. 13, the electronic device may include: a processor (processor)1310, a communication Interface (Communications Interface)1320, a memory (memory)1330 and a communication bus 1340, wherein the processor 1310, the communication Interface 1320 and the memory 1330 communicate with each other via the communication bus 1340. The processor 1310 may call logic instructions in the memory 1330 to perform the following method: determining a space area corresponding to a query request according to position information when the user initiates the query request; searching a candidate query result set corresponding to the query request in the space region according to the text description information of the query request; determining a feature vector of text description information of the query request and a feature vector of each candidate query result in the candidate query result set according to a preset mapping relation between words and word embedding vectors; the word embedding vector reflects the association degree between a word and other words in the text where the word is located and the association degree between the word and a space region; the feature vector is obtained according to the word embedding vector of the word contained in the text description information or the candidate query result; and sequencing each candidate query result in the candidate query result set according to the distance between the characteristic vector of each candidate query result in the candidate query result set and the characteristic vector of the text description information of the query request, and returning the sequence to the user.
It should be noted that, when the electronic device in this embodiment is implemented specifically, the electronic device may be a server, a PC, or other devices, as long as the structure includes the processor 1310, the communication interface 1320, the memory 1330 and the communication bus 1340 shown in fig. 13, where the processor 1310, the communication interface 1320, and the memory 1330 complete mutual communication through the communication bus 1340, and the processor 1310 may call the logic instructions in the memory 1330 to execute the above method. The embodiment does not limit the specific implementation form of the electronic device.
In addition, the logic instructions in the memory 1330 may be implemented in software functional units and stored in a computer readable storage medium when sold or used as a stand-alone product. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to perform all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
Further, the present invention discloses a computer program product, the computer program product includes a computer program stored on a non-transitory computer readable storage medium, the computer program includes program instructions, when the program instructions are executed by a computer, the computer can execute the method provided by the above method embodiments, for example, the method includes: determining a space area corresponding to a query request according to position information when the user initiates the query request; searching a candidate query result set corresponding to the query request in the space region according to the text description information of the query request; determining a feature vector of text description information of the query request and a feature vector of each candidate query result in the candidate query result set according to a preset mapping relation between words and word embedding vectors; the word embedding vector reflects the association degree between a word and other words in the text where the word is located and the association degree between the word and a space region; the feature vector is obtained according to the word embedding vector of the word contained in the text description information or the candidate query result; and sorting and returning each candidate query result in the candidate query result set to the user according to the distance between the feature vector of each candidate query result in the candidate query result set and the feature vector of the text description information of the query request.
In another aspect, an embodiment of the present invention further provides a non-transitory computer-readable storage medium, on which a computer program is stored, where the computer program is implemented by a processor to perform the method provided by the foregoing embodiments, for example, including: determining a space area corresponding to a query request according to position information when the user initiates the query request; searching a candidate query result set corresponding to the query request in the space region according to the text description information of the query request; determining a feature vector of text description information of the query request and a feature vector of each candidate query result in the candidate query result set according to a mapping relation between preset words and word embedding vectors; the word embedding vector reflects the association degree between a word and other words in the text where the word is located and the association degree between the word and a space region; the feature vector is obtained according to the word embedding vector of the word contained in the text description information or the candidate query result; and sorting and returning each candidate query result in the candidate query result set to the user according to the distance between the feature vector of each candidate query result in the candidate query result set and the feature vector of the text description information of the query request.
The above-described embodiments of the apparatus are merely illustrative, and the units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented by software plus a necessary general hardware platform, and of course, can also be implemented by hardware. With this understanding in mind, the above technical solutions may be embodied in the form of a software product, which can be stored in a computer readable storage medium, such as ROM/RAM, magnetic disk, optical disk, etc., and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute the method according to the embodiments or some parts of the embodiments.
Finally, it should be noted that: the above examples are only intended to illustrate the technical solution of the present invention, but not to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.

Claims (10)

1. A method of querying, comprising:
determining a space area corresponding to a query request according to position information when the user initiates the query request;
searching a candidate query result set corresponding to the query request in the space region according to the text description information of the query request;
determining a feature vector of text description information of the query request and a feature vector of each candidate query result in the candidate query result set according to a preset mapping relation between words and word embedding vectors; the word embedding vector reflects the association degree between a word and other words in the text where the word is located and the association degree between the word and a space region; the feature vector is obtained according to the word embedding vector of the word contained in the text description information or the candidate query result;
and sorting and returning each candidate query result in the candidate query result set to the user according to the distance between the feature vector of each candidate query result in the candidate query result set and the feature vector of the text description information of the query request.
2. The query method according to claim 1, wherein before the step of determining the spatial region corresponding to the query request according to the location information when the user initiates the query request, the method further comprises:
acquiring sample space data, wherein the sample space data comprises position information and text description information;
generating corresponding word embedding vectors for each word in the text description information according to the position information and the text description information;
and establishing a mapping relation between the words and the corresponding word embedding vectors.
3. The query method according to claim 2, wherein the generating a corresponding word embedding vector for each word in the text description information according to the location information and the text description information specifically includes:
determining a space sub-region where a word is located for each word in the text description information in a quad-tree division mode by combining the position information; obtaining a space position coding vector and a space influence vector corresponding to each word according to the space subregion where each word in the text description information is located; wherein the spatial sub-region is a result of index space segmentation;
performing space fusion on each word in the text description information according to the space position coding vector and the space influence vector of each word in the text description information to obtain a space fusion vector containing association degrees of the words and different space subregions;
gathering the space sub-regions, and replacing words in the gathered space sub-regions with space fusion vectors of the words; calculating the space attention value of the word according to the space fusion backward quantity of the word in the gathered space subregion and the space influence vector of the word to obtain the space attention vector of the word; the spatial attention vector is used for highlighting the influence of the spatial position;
obtaining a corresponding word embedding vector according to the space attention vector of the word, the influence vector of the word and the region vector of the word; wherein the influence vector of the word is generated by the space attention vector of the word and the space influence vector of the word; the region vector of the word refers to a coding vector corresponding to a subspace region divided by the quadtree.
4. The query method according to claim 3, wherein the performing spatial fusion on each word in the text description information according to the spatial position coding vector and the spatial influence vector of each word in the text description information to obtain a spatial fusion vector used for reflecting the degree of association between one word and different spatial sub-regions specifically comprises:
inputting the space position coding vector and the space influence vector of each word in the text description information into a word space fusion model to obtain a space fusion vector of each word in the text description information; wherein the content of the first and second substances,
the word space fusion model comprises a one-dimensional convolution layer and a feedforward neural network; wherein the content of the first and second substances,
the one-dimensional convolutional layer extracts effective features in the space position coding vector through a convolutional kernel function, and eliminates a space sub-region with space influence lower than a preset threshold according to the space influence vector;
the feedforward neural network comprises an input layer, a hidden layer and an output layer, wherein only one hidden layer is arranged, and the output layer sets inverted quadtree coding of a first word for the first word to be predicted by the input layer; and the objective function of the feedforward neural network is used for realizing the fusion judgment of the position information and the text description information.
5. The query method according to claim 3, wherein the aggregating the spatial sub-regions and replacing words in the aggregated spatial sub-regions with the spatially fused vectors of the words specifically comprises:
gathering the space sub-regions through a convolution layer part of the space attention model, and replacing words in the gathered space sub-regions with space fusion vectors of the words; the convolutional layer part of the spatial attention model comprises a plurality of convolutional layers which are sequentially stacked, and the convolutional layers are used for realizing aggregation of the spatial sub-regions and association between the aggregated spatial sub-regions and the word set;
correspondingly, the calculating the spatial attention value of the word according to the spatial fusion backward quantity of the word in the collected spatial subregion and the spatial influence vector of the word to obtain the spatial attention vector of the word specifically includes:
inputting the space attention layer part of the space attention model according to the space fusion backward vector of the words in the gathered space subarea, and calculating the space attention value of the words by combining the space attention layer part with the space influence vector of the words to obtain the space attention vector of the words; wherein the spatial attention layer portion of the spatial attention model is stacked with a plurality of spatial attention layers for emphasizing the influence of spatial position in the spatial fusion backmeasure of words within the post-aggregation spatial subregion.
6. The query method according to claim 3, wherein obtaining the corresponding word embedding vector according to the spatial attention vector of the word, the influence vector of the word, and the region vector of the word specifically includes:
taking the space attention vector of the word, the influence vector of the word and the area vector of the word as input data of a BERT model, training a Mask LM (real time language) task on the BERT model, and outputting a word space association degree vector for reflecting the association degree between the word and the space area by the BERT model after the training of the Mask LM task is finished;
setting a first label for a word in a preset space subregion set according to the word space relevance vector, then randomly selecting a word in the preset space subregion according to a preset proportion, replacing the selected word with a word outside the preset space subregion set, and setting a second label for the replaced word; randomly selecting two words in the preset space sub-area, determining a CLS mark of a word vector according to a comparison result, and finally inputting the word vector into the BERT model, wherein the BERT model outputs a word embedding vector; wherein the content of the first and second substances,
the preset space subregion set is a set of the preset space subregion and an adjacent space subregion thereof.
7. The query method according to claim 1, wherein the determining, according to a mapping relationship between preset words and word embedding vectors, a feature vector of text description information of the query request and feature vectors of each candidate query result in the candidate query result set specifically includes:
performing word segmentation operation on the text description information of the query request, determining corresponding word embedding vectors for words in the text description information obtained by the word segmentation operation according to a preset mapping relation between the words and the word embedding vectors, and determining feature vectors of the text description information according to the word embedding vectors of all the words in the text description information;
performing word segmentation operation on each candidate query result in the candidate query result set, determining a corresponding word embedding vector for a word in each candidate query result obtained by the word segmentation operation according to a preset mapping relation between the word and the word embedding vector, and determining a feature vector of each candidate query result in the candidate query result set according to the word embedding vector of each word in each candidate query result.
8. An inquiry apparatus, comprising:
the device comprises a space region determining module, a searching module and a searching module, wherein the space region determining module is used for determining a space region corresponding to a searching request according to position information when the user initiates the searching request;
a candidate query result set determining module, configured to search, according to the text description information of the query request, a candidate query result set corresponding to the query request in the spatial region;
the characteristic vector determining module is used for determining a characteristic vector of text description information of the query request and a characteristic vector of each candidate query result in the candidate query result set according to a preset mapping relation between words and word embedded vectors; the word embedding vector reflects the association degree between a word and other words in the text where the word is located and the association degree between the word and a space region; the feature vector is obtained according to the word embedding vector of the word contained in the text description information or the candidate query result;
and the distance calculation and sorting module is used for sorting and returning each candidate query result in the candidate query result set to the user according to the distance between the feature vector of each candidate query result in the candidate query result set and the feature vector of the text description information of the query request.
9. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the steps of the query method according to any one of claims 1 to 7 are implemented when the processor executes the program.
10. A non-transitory computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the query method according to any one of claims 1 to 7.
CN202011078854.3A 2020-10-10 2020-10-10 Query method, query device, electronic equipment and storage medium Active CN112632406B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011078854.3A CN112632406B (en) 2020-10-10 2020-10-10 Query method, query device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011078854.3A CN112632406B (en) 2020-10-10 2020-10-10 Query method, query device, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN112632406A true CN112632406A (en) 2021-04-09
CN112632406B CN112632406B (en) 2024-04-09

Family

ID=75302784

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011078854.3A Active CN112632406B (en) 2020-10-10 2020-10-10 Query method, query device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN112632406B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115408568A (en) * 2021-05-26 2022-11-29 中科寒武纪科技股份有限公司 Method for fusing operators of neural network and related product
CN116108072A (en) * 2023-04-04 2023-05-12 阿里巴巴(中国)有限公司 Data query method and query prediction model training method

Citations (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104679904A (en) * 2015-03-20 2015-06-03 苏州大学张家港工业技术研究院 Position point query method and device for road network
CN104965859A (en) * 2015-06-02 2015-10-07 百度在线网络技术(北京)有限公司 Method and apparatus for obtaining candidate address information in map
CN105392117A (en) * 2015-10-19 2016-03-09 腾讯科技(深圳)有限公司 Method and device for querying short-distance object
CN106407280A (en) * 2016-08-26 2017-02-15 合网络技术(北京)有限公司 Query target matching method and device
CN107491547A (en) * 2017-08-28 2017-12-19 北京百度网讯科技有限公司 Searching method and device based on artificial intelligence
CN108009205A (en) * 2017-11-02 2018-05-08 口碑(上海)信息技术有限公司 Location-based search result caching method, searching method, client and system
KR20180058449A (en) * 2016-11-24 2018-06-01 주식회사 솔트룩스 System and method of semantic search using word vector
CN108306812A (en) * 2017-02-08 2018-07-20 腾讯科技(深圳)有限公司 A kind of data processing method and server
CN108875007A (en) * 2018-06-15 2018-11-23 腾讯科技(深圳)有限公司 The determination method and apparatus of point of interest, storage medium, electronic device
CN110674419A (en) * 2019-01-25 2020-01-10 北京嘀嘀无限科技发展有限公司 Geographic information retrieval method and device, electronic equipment and readable storage medium
CN110968800A (en) * 2019-11-26 2020-04-07 北京明略软件系统有限公司 Information recommendation method and device, electronic equipment and readable storage medium
CN111078842A (en) * 2019-12-31 2020-04-28 北京每日优鲜电子商务有限公司 Method, device, server and storage medium for determining query result
CN111177551A (en) * 2019-12-27 2020-05-19 百度在线网络技术(北京)有限公司 Method, device, equipment and computer storage medium for determining search result
WO2020103783A1 (en) * 2018-11-19 2020-05-28 阿里巴巴集团控股有限公司 Method for determining address text similarity, address searching method, apparatus, and device

Patent Citations (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104679904A (en) * 2015-03-20 2015-06-03 苏州大学张家港工业技术研究院 Position point query method and device for road network
CN104965859A (en) * 2015-06-02 2015-10-07 百度在线网络技术(北京)有限公司 Method and apparatus for obtaining candidate address information in map
CN105392117A (en) * 2015-10-19 2016-03-09 腾讯科技(深圳)有限公司 Method and device for querying short-distance object
CN106407280A (en) * 2016-08-26 2017-02-15 合网络技术(北京)有限公司 Query target matching method and device
KR20180058449A (en) * 2016-11-24 2018-06-01 주식회사 솔트룩스 System and method of semantic search using word vector
CN108306812A (en) * 2017-02-08 2018-07-20 腾讯科技(深圳)有限公司 A kind of data processing method and server
CN107491547A (en) * 2017-08-28 2017-12-19 北京百度网讯科技有限公司 Searching method and device based on artificial intelligence
CN108009205A (en) * 2017-11-02 2018-05-08 口碑(上海)信息技术有限公司 Location-based search result caching method, searching method, client and system
CN108875007A (en) * 2018-06-15 2018-11-23 腾讯科技(深圳)有限公司 The determination method and apparatus of point of interest, storage medium, electronic device
WO2020103783A1 (en) * 2018-11-19 2020-05-28 阿里巴巴集团控股有限公司 Method for determining address text similarity, address searching method, apparatus, and device
CN110674419A (en) * 2019-01-25 2020-01-10 北京嘀嘀无限科技发展有限公司 Geographic information retrieval method and device, electronic equipment and readable storage medium
CN110968800A (en) * 2019-11-26 2020-04-07 北京明略软件系统有限公司 Information recommendation method and device, electronic equipment and readable storage medium
CN111177551A (en) * 2019-12-27 2020-05-19 百度在线网络技术(北京)有限公司 Method, device, equipment and computer storage medium for determining search result
CN111078842A (en) * 2019-12-31 2020-04-28 北京每日优鲜电子商务有限公司 Method, device, server and storage medium for determining query result

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
高勇;姜丹;刘磊;林星;邬伦;: "一种地理信息检索的定性模型", 北京大学学报(自然科学版), vol. 52, no. 02, 31 March 2016 (2016-03-31) *

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115408568A (en) * 2021-05-26 2022-11-29 中科寒武纪科技股份有限公司 Method for fusing operators of neural network and related product
CN115408568B (en) * 2021-05-26 2024-04-05 中科寒武纪科技股份有限公司 Method for fusing operators of neural network and related products
CN116108072A (en) * 2023-04-04 2023-05-12 阿里巴巴(中国)有限公司 Data query method and query prediction model training method
CN116108072B (en) * 2023-04-04 2023-09-19 阿里巴巴(中国)有限公司 Data query method and query prediction model training method

Also Published As

Publication number Publication date
CN112632406B (en) 2024-04-09

Similar Documents

Publication Publication Date Title
CN109918532B (en) Image retrieval method, device, equipment and computer readable storage medium
CN110795543B (en) Unstructured data extraction method, device and storage medium based on deep learning
WO2021147726A1 (en) Information extraction method and apparatus, electronic device and storage medium
CN108875074B (en) Answer selection method and device based on cross attention neural network and electronic equipment
US20170249339A1 (en) Selected image subset based search
CN111046132A (en) Customer service question and answer processing method and system for retrieving multiple rounds of conversations
CN112100426B (en) Method and system for universal form information retrieval based on visual and text features
CN112364238B (en) Deep learning-based user interest point recommendation method and system
CN110928961A (en) Multi-mode entity linking method, equipment and computer readable storage medium
CN112632406B (en) Query method, query device, electronic equipment and storage medium
CN112347223A (en) Document retrieval method, document retrieval equipment and computer-readable storage medium
CN115982338A (en) Query path ordering-based domain knowledge graph question-answering method and system
CN111723306A (en) Sequence position recommendation method based on geographical perception
CN112579816B (en) Remote sensing image retrieval method and device, electronic equipment and storage medium
CN105183845A (en) ERVQ image indexing and retrieval method in combination with semantic features
CN115797795A (en) Remote sensing image question-answering type retrieval system and method based on reinforcement learning
CN114694185B (en) Cross-modal target re-identification method, device, equipment and medium
CN115203206A (en) Data content searching method and device, computer equipment and readable storage medium
CN110210034B (en) Information query method, device, terminal and storage medium
CN113157892A (en) User intention processing method and device, computer equipment and storage medium
CN113392312A (en) Information processing method and system and electronic equipment
CN117808923B (en) Image generation method, system, electronic device and readable storage medium
CN117473071B (en) Data retrieval method, device, equipment and computer readable medium
CN117938951B (en) Information pushing method, device, computer equipment and storage medium
CN112507912B (en) Method and device for identifying illegal pictures

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
GR01 Patent grant