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

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

Info

Publication number
CN112632406B
CN112632406B CN202011078854.3A CN202011078854A CN112632406B CN 112632406 B CN112632406 B CN 112632406B CN 202011078854 A CN202011078854 A CN 202011078854A CN 112632406 B CN112632406 B CN 112632406B
Authority
CN
China
Prior art keywords
word
vector
space
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.)
Active
Application number
CN202011078854.3A
Other languages
Chinese (zh)
Other versions
CN112632406A (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

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

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 region corresponding to a query request according to position information when a 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; according to a preset mapping relation between words and word embedding vectors, determining feature vectors of text description information of the query request and feature vectors of each candidate query result in the candidate query result set; and sequencing and returning each candidate query result in the candidate query result set to a 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, query 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 computer is queried, a word embedding method is generally adopted to calculate the feature vector of a word to be queried and the feature vector of a candidate word, then the semantic relativity 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 relativity.
There are various word embedding methods in the prior art, such as word2 vec-based word embedding method proposed by google corporation, a transducer model proposed by google corporation, and a BERT model.
Although the word embedding methods in the prior art have a great improvement in performance, all the methods only consider the characteristics of the text, but do not consider other characteristics attached to the text.
For example, in the context of a spatial data application, each spatial object contains not only text description information, but also location information. In some cases the semantics of the text may be affected by the spatial location where it is located.
For example, when a user searches for "a park" in the search system, and the candidate result returned by the search system comprises two places which are far away from each other, the result "a garden" is closer to the search word "a park" from text semantics, but the user may be near the a stadium when initiating the search, and the real intention is to find a way to the a stadium, and then the similarity between the search word and the candidate result is determined according to the text semantics only, so that the search result is deviated.
As can be seen from the above examples, in the context of spatial data applications, it is necessary to combine text information with location information to obtain a correct query result.
In the prior art, when processing space data, text information and position information are processed separately, and accurate association cannot be established between the text information and the position information of the space data; the existing word vector coding model cannot show the association between the word and the position information, and even if a spatial position vector is added in the BERT model, the position information can be lost when the model is trained, so that the model cannot acquire the implicit semantics of the spatial 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
Aiming at the problems existing in the prior art, the embodiment of the invention provides a query method, a query device, electronic equipment and a storage medium.
In a first aspect, an embodiment of the present invention provides a query method, including:
determining a space region corresponding to a query request according to position information when a 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;
according to a preset mapping relation between words and word embedding vectors, determining feature vectors 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 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 according to the text description information or word embedding vectors of words contained in the candidate query results;
and sequencing each candidate query result in the candidate query result set 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, and returning the sequencing result to the user.
In the above technical solution, before the step of determining the spatial area 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 above technical solution, the generating, according to the location information and the text description information, a corresponding word embedding vector for each word in the text description information specifically includes:
combining the position information, and determining a space subarea where the word is located for each word in the text description information in a quadtree division mode; according to the space subarea where each word in the text description information is located, obtaining a space position coding vector and a space influence vector corresponding to each word; wherein the space subarea is the result of index space segmentation;
according to the spatial position coding vector and the spatial influence vector of each word in the text description information, carrying out spatial fusion on each word in the text description information to obtain a spatial fusion post-vector containing the association degree of the word and different spatial subareas;
Aggregating the space subareas, and replacing words in the aggregated space subareas with space fusion vectors of the words; according to the space fusion post-vectors of the words in the collected space subareas and the space influence vectors of the words, calculating the space attention value of the words to obtain the space attention vectors of the words; the spatial attention vector is used for highlighting the influence of the spatial position;
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; wherein the influence vector of the word is generated by the spatial attention vector of the word and the spatial influence vector of the word; the regional vector of the word refers to the coding vector corresponding to the subspace region after the quadtree is divided.
According to the technical scheme, the spatial fusion is carried out 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 the spatial fusion post-vector for reflecting the association degree of one word and different spatial subregions, and the method specifically comprises the following steps:
inputting the spatial position coding vector and the spatial influence vector of each word in the text description information into a word spatial fusion model to obtain a spatial fusion post-vector of each word in the text description information; wherein,
The word space fusion model comprises a one-dimensional convolution layer and a feedforward neural network; wherein,
the one-dimensional convolution layer extracts effective features in the spatial position coding vector through a convolution kernel function, and eliminates a spatial subarea with a spatial influence lower than a preset threshold according to the spatial influence vector;
the feedforward neural network comprises an input layer, a hidden layer and an output layer, wherein only one hidden layer exists, and the output layer sets inverted quadtree codes of first words for the first words to be predicted by the input layer; and the objective function of the feedforward neural network is used for realizing fusion judgment of the position information and the text description information.
In the above technical solution, the aggregating the space subregions, and replacing the word in the aggregated space subregion with the space fusion vector of the word, specifically includes:
gathering the space subareas through a convolution layer part of the space attention model, and replacing words in the gathered space subareas with space fusion vectors of the words; the convolution layer part of the spatial attention model comprises a plurality of convolution layers which are stacked in sequence, and the convolution layers are used for realizing aggregation of the spatial subregions and association between the aggregated spatial subregions and the word sets;
Correspondingly, the calculating the spatial attention value of the word according to the spatial fusion post-vector of the word in the collected spatial subarea and the spatial influence vector of the word to obtain the spatial attention vector of the word specifically comprises the following steps:
inputting the spatially fused vectors of the words in the aggregated spatial subregions into a spatial attention layer part of the spatial attention model, and calculating the spatial attention value of the words by combining the spatial attention layer part with the spatial attention vector of the words to obtain the spatial attention vector of the words; 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 the spatial position in the spatially fused vector of words in the clustered spatial sub-regions.
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 spatial attention vector of the word, the influence vector of the word and the region vector of the word as input data of a BERT model, training a Mask LM task on the BERT model, and outputting a word spatial association vector for reflecting association between the word and a spatial region by the BERT model after the Mask LM task training is finished;
Setting a first label for words in a preset space subarea set according to the word space relevance vector, randomly selecting words in the preset space subarea according to a preset proportion, replacing the selected words with words outside the preset space subarea set, and setting a second label for the replaced words; randomly selecting two words in the preset space subarea, determining a CLS mark of a word vector according to a comparison result, and finally inputting the BERT model, wherein the BERT model outputs a word embedded vector; wherein,
the preset space subarea set is a set of the preset space subarea and adjacent space subareas thereof.
In the above technical solution, the determining, according to a mapping relationship between a preset word and a word embedding vector, 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 specifically includes:
word segmentation operation is carried out on the text description information of the query request, corresponding word embedding vectors are determined for words in the text description information obtained through the word segmentation operation according to a preset mapping relation between words and word embedding vectors, and feature vectors of the text description information are determined according to the word embedding vectors of all 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 the 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 a query device, including:
the space region determining module is used for determining a space region corresponding to the query request according to the position information when the user initiates the query request;
the candidate query result set determining module is used for 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;
the feature vector determining module is used for determining feature vectors 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 relation between words and word embedding vectors; 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 according to the text description information or word embedding vectors of words contained in the candidate query results;
And the distance calculating and sorting module is used for sorting the candidate query results in the candidate query result set according to the distance between the feature vector of the candidate query result in the candidate query result set and the feature vector of the text description information of the query request and returning the sorted candidate query result to the user.
In a third aspect, an embodiment of the present invention provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor, where the processor implements the steps of the query method according to the embodiment of the first aspect of the present invention when the processor executes the program.
In a fourth aspect, embodiments of the present invention provide a non-transitory computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of a query method according to embodiments of the first aspect of the present invention.
When the query method, the device, the electronic equipment and the storage medium provided by the embodiment of the invention are used for carrying out query operation, the candidate result set in the specific space area is searched according to the position information of the query request, and then the feature vector combining the text information and the position information of the query request is compared with the feature vector combining the text information and the position information of the candidate result set, so that the query result is determined in the candidate result set. The query result is more accurate because the location information is added instead of just the text information during the query.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, a brief description will be given below of the drawings required for the embodiments or the description of the prior art, and it is obvious that the drawings in the following description are some embodiments of the present invention, and other drawings can be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flowchart of a query method provided in an embodiment of the present invention;
FIG. 2 is a schematic diagram of indexing sample space data using a quadtree in one embodiment;
FIG. 3 is a schematic structural diagram of a word space fusion model involved in a query method according to an 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 present invention;
FIG. 5 is a flowchart of operations to be performed by a convolution layer in a spatial attention model according to an exemplary embodiment of the present invention;
FIG. 6 is a schematic structural diagram of a spatial attention layer in a spatial attention model according to an embodiment of the present invention;
FIG. 7 is a schematic diagram of word vector merging performed by a spatial attention layer in a spatial attention model 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 according to an exemplary 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 for weakening irrelevant word space relevance by a space text prediction task in a BERT model in a query method provided by an embodiment of the invention;
FIG. 12 is a schematic diagram of a query device according to an embodiment of the present invention;
fig. 13 is a schematic diagram of an entity structure of an electronic device related to a query method according to an embodiment of the present invention.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention, and it is apparent that the described embodiments are some embodiments of the present invention, but not all embodiments of the present invention. All other embodiments, which can be made by one of ordinary skill in the art without undue burden on the person of ordinary skill in the art 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 provided by an embodiment of the present invention, where, as shown in fig. 1, the query method provided by the embodiment of the present invention includes:
step 101, determining a space region corresponding to a query request according to position information when a user initiates the query request.
In the embodiment of the invention, when the user initiates the query request, the position where the user is the position information when the user initiates the query request. The location information may be latitude and longitude coordinate information. The location information can be obtained through a terminal device with a positioning function of a user, such as a movable intelligent terminal device, including a smart phone, a smart watch, a tablet computer, a notebook computer and the like. The terminal equipment of the user obtains the position information of the user when the inquiry request is initiated through a satellite positioning module such as a GPS positioning module, a Beidou positioning module and the like.
In the embodiment of the invention, when a user initiates a query request, query content input by the user is called text description information. The "a park" as entered by the user within the search box is the text description of the query request.
In a query operation related to location information, a query result desired by a general user is a query result adjacent to a current location of the user. For example, a user queries "people parks", hundreds or thousands of "people parks" around the country, and if the user does not add a specific qualifier, such as "Shanghai people parks", before the keyword "people parks", then the "people parks" that the user living in the jalousie generally wishes to find are people parks closest to him, such as "jalousie people parks". Therefore, in this step, the spatial region to which the user belongs is determined based on the position information at the time of the user's initiation of the query request.
The division of the spatial area may be preset, for example, the spatial area is divided in a quadtree division manner, and in the embodiment of the present invention, the method for dividing the spatial area is not limited.
The spatial regions have identifiers that distinguish one from another, such as by uniquely marking one spatial region with a number. Other types of representation manners, such as combining a place name and a number, taking a postal code as an identifier of a space area, and the like, can also be adopted by the identifier, and the representation manner of the space area is not limited in the embodiment of the 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. And searching a corresponding space region according to the longitude and latitude coordinate information.
Step 102, 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.
In the previous step, the space area to which the query request belongs is determined according to the position information in the query request, and in the present step, a candidate query result set corresponding to the query request is searched in the space area corresponding to the query request according to the words contained in the text description information of the query request.
Specifically, words contained in the text description information can be used as keywords, and candidate query results can be searched in a specific space area in a fuzzy matching mode. Since there are typically a plurality of candidate query results, a set of candidate query results may be generated.
For example, if a user initiates a query request for searching for "people parks" in Jiaxing city, the query request corresponds to the space region of Jiaxing city, and the candidate query result corresponding to the query request is the result related to "people parks" in the region of Jiaxing city, but not the result related to "people parks" in the region of Shanghai city or Cheng city.
The candidate query results are spatial data that includes not only textual description information, but also location information. For example, a candidate result not only includes text description information of a people park, but also includes longitude and latitude coordinate information of the park.
And step 103, determining the feature vector of the text description information of the query request and the feature vector of each candidate query result in the candidate query result set according to the preset mapping relation between the word and the word embedding vector.
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 derived from the text description information or a word embedding vector of words contained in the candidate query result.
In the embodiment of the invention, the mapping relation between words and word embedding vectors can be expressed in the following way: { words, word embedded vector }. According to the mapping relation between the words and the word embedding vectors, the corresponding word embedding vectors can be found for the words.
The mapping relationship between the word and the word embedding vector can be stored in a database, such as a Redis database, wherein 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 word and the word embedding vector is generated in advance based on the sample space data, and in other embodiments of the present invention, a process of how to generate the mapping relationship between the word and the word embedding vector from the sample space data will be described in detail.
The implementation process of the step specifically comprises the following steps:
word segmentation operation is carried out on the text description information of the query request, corresponding word embedding vectors are determined for words in the text description information obtained through the word segmentation operation according to a preset mapping relation between words and word embedding vectors, and feature vectors of the text description information are determined according to the word embedding vectors of all 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 the 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 above implementation process, the word segmentation operation is common knowledge of a person skilled in the art, and in the embodiment of the present invention, implementation details of the word segmentation operation are not further described.
After obtaining the text description information of the query request or the word vector of each word in the candidate query result, the feature vector of the whole text description information or the candidate query result can be further obtained from the word vector of the single word. For example, weighted average calculation is performed on word vectors of all words contained in the text description information or the candidate query result, so as to obtain feature vectors of the whole text description information or the candidate query result. Other calculation methods may be used to calculate the feature vector of the entire text description information or candidate query results, which is not limited in the embodiment of the present invention.
Step 104, sorting the candidate query results in the candidate query result set 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, and returning the sorted candidate query results to the user.
In the embodiment of the invention, a method for calculating the cosine distance can be adopted when calculating the distance value. Assuming Vq is a feature vector of text description information of the query request, vr is a feature vector of a certain candidate result, and the calculation formula of the cosine distance is as follows:
D=cos_sine(Vq,Vr);
where cos_sine is a cosine distance calculation function.
After the distance value is obtained through calculation, the candidate results are ordered in a reverse order, the candidate results with the front order are more closely related to the query request of the user, the possibility of the candidate results being the query results required by the user is higher, and the ordered candidate results can be output to the user for selection by the user.
When the query method provided by the embodiment of the invention is used for carrying out query operation, the candidate result set in the specific space area is searched according to the position information of the query request, and then the feature vector combining the text information and the position information of the query request is compared with the feature vector combining the text information and the position information of the candidate result set, so that the query result is determined in the candidate result set. The query result is more accurate because the location information is added instead of just the text information during the query.
Based on any 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 word and the word embedding vector is preset, and in the embodiment of the present invention, the mapping relationship between the word and the word embedding vector is generated according to the sample space data.
The sample space data is space data as a sample, and the space data is data containing position information, and the space data generally comprises text description information and the position information. The text description information mainly relates to the content of text, and four words such as 'people parks' belong to the text description information. Location information, as the name implies, is used to represent spatial locations, 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, north latitude 31.232229", then the coordinate value is the location information of the "people park".
From the above illustration, the place names in the map are more typical spatial data.
The format of the spatial Data may be data= < p, t >, where p is the position information of the spatial Data and t is the 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 and the text description information of the sample space data. The method specifically comprises the following steps:
step S1, combining the position information, and determining a space subarea where the word is located for each word in the text description information in a quadtree division mode; according to the space subarea where each word in the text description information is located, obtaining a space position coding vector and a space influence vector corresponding to each word; wherein the space subarea is the result of index space segmentation;
s2, carrying out 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 fused vector containing the association degree of the word and different space subareas;
S3, gathering the space subareas, and replacing words in the gathered space subareas with space fusion vectors of the words; according to the space fusion post-vectors of the words in the collected space subareas and the space influence vectors of the words, calculating the space attention value of the words to obtain the space attention vectors of the words; 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 spatial 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 from the spatial attention vector of the word and the spatial influence vector of the word; the regional vector of the word refers to the coding vector corresponding to the subspace region after the quadtree is divided.
According to the query method provided by the embodiment of the invention, the word embedding vector corresponding to the word is obtained by performing a plurality of operations such as space position coding, space influence coding, word fusion, attention calculation and the like on the word in the text description information according to the position information and the text description information contained in the sample space data, so that the mapping relation between the word and the word embedding vector is generated, and a good foundation is laid for the subsequent query operation.
Based on any of the foregoing embodiments, in an embodiment of the present invention, the step S1 specifically includes:
firstly, word segmentation operation is carried out on text description information in the space data, and each word contained in the text description information is obtained.
And then, coding the word according to the association relation between the word and the position information of the space data to obtain a space position coding vector.
The purpose of encoding words is to establish an association between words of sample space data and location information. In the embodiment of the invention, the spatial position coding vector of the word is constructed based on the coding mode of the spatial text index.
Specifically, the sample space data is first indexed using a quadtree that divides the index space into different subspaces. FIG. 2 is a schematic diagram of sample space data indexed using a quadtree in one embodiment. 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 (no numbers 1,2, and 3 are shown in fig. 2 because the number of corresponding sub-regions is 0,1,2, 3 if the 0 sub-region is divided into 4 blocks according to the rule of Z-order).
A set of words contained in a sub-region within a smaller range can be derived from a set of keywords contained in sample space data within a sub-region. A vector representation is set based on the spatial region coding method, which is referred to as a spatial position coding vector in the present embodiment, since it can describe the association between words of sample spatial data and position information.
Specifically, in the encoding process, the value in each spatial position encoding vector is ordered from low to high according to the Z-order number of the spatial region, and if the subarea contains the corresponding word, 1 is filled, and if the subarea does not contain the corresponding word, 0 is filled. For example, in the subregion profile shown in fig. 2, it is assumed that only subregions 0, 9, 12 contain the word "restaurant", the vector of which is expressed as:
BVec <restaurant and restaurant> =<1,0,0,0,0,0,0,0,0,1,0,0,1>;
The vectors are 13-dimensional and correspond to sub-regions numbered from 0 to 12, respectively, and although the sub-regions numbered 1, 2, and 3 are not divided in the embodiment shown in fig. 2, the dimensions corresponding to the sub-regions numbered 1, 2, and 3 are included in the vectors for the convenience of vector representation and calculation.
By the spatial position coding vector of the words constructed by the spatial text index-based coding mode, whether one spatial subarea comprises a word or not can be described, 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.
With reference to the above coding method, all words are coded, and the coding results are combined into a base_word matrix, each row of the matrix is a spatial position coding vector of a Word, and the number of rows of the matrix depends on the number of words contained in the text description information of the spatial data.
Finally, according to the distribution of the space data in each subarea, the influence of the words in the space data in each subarea can be calculated.
The influence can be represented by an influence factor, and the calculation formula of the influence factor is as follows:
C e =Num word /Num all
wherein Num is word Representing the number of spatial data containing word in one sub-area, num all Representing the amount of all spatial data within a sub-area.
Based on the influence factor, a spatial influence vector of the word can be further obtained. One word corresponds to one spatial influence vector, the column of the spatial influence vector corresponds to the sub-region in which the word is located, and the column stores the influence factor of the word on the sub-region to which the column corresponds.
The spatial influence vectors of the plurality of words may form a spatial influence matrix ce_word, the rows of the matrix corresponding to a Word, the columns corresponding to the sub-regions in which the Word is located, and for the columns corresponding to the sub-regions containing a Word, the influence factors of the Word for the sub-regions are stored.
From the calculation formula of the influence factor, it can be seen that the larger the number of words contained in a certain subarea, the larger the influence of the words on the subarea.
For example, in the influence matrix ce_word, the data of the row corresponding to the Word "restaurant" may have the following 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 will also have similar forms.
The query method provided by the embodiment of the invention realizes the generation of the spatial position coding vector and the spatial influence vector of the word.
Based on any of the foregoing embodiments, in an embodiment of the present invention, the step S2 specifically includes:
and inputting the spatial position coding vector and the spatial influence vector of each word in the text description information into a word spatial fusion model to obtain a spatial fusion post-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 location encoding vector can describe whether a spatial sub-region includes a word, a simple association of the word with the spatial location is established. In order to further understand the degree of association between the spatial subregion and the word, in an embodiment of the present invention, a word space fusion model (ws 2vec: word spatial to vector) is used to learn the association of the word in the spatial position.
Fig. 3 is a schematic diagram of a word space fusion model, and as shown in fig. 3, the word space fusion model may be divided into two parts, wherein the first part is a one-dimensional convolution layer, and the second part is a feedforward neural network similar to the word2vec model and only including 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 spatial position coding vector through a convolution kernel function 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(x i )=f(x i-j ,…,x i-1 ,x i ,x i+1 ,…,x i+j )g(Ce_Word[word,i],2j+1);
wherein i is the column coordinate in the spatial position coding vector of the word, namely the sub-region code corresponding to the word, j is the convolution kernel length coefficient, and one-dimensional convolution can be seen from the aboveLength 2j+1; the function f () is a convolution kernel calculation function, x i Is the encoded value that participates in the convolution operation.
The significant features in the spatial position encoded vector extracted by the convolution kernel function may be represented by W i And (3) representing.
In the embodiment of the invention, the values of the columns of the plurality of spatial position coding vectors can be considered together by adopting one-dimensional convolution, so that the relation of the same word on different subareas is established, wherein the value of j can be selected according to actual conditions.
The one-dimensional convolution layer can also eliminate the subareas with too low influence, namely, the subareas are subjected to filtering operation. Specifically, the influence distribution of a word in each space subarea is obtained from the space influence matrix of the word, the value of the influence distribution is subjected to vector multiplication with the code value participating in convolution operation, and an influence threshold value theta is set. And removing the areas with low influence, namely setting the value of the column of the space word vector with the value smaller than theta to 0, so as to eliminate noise, and removing the influence of the space subarea with low influence on word space position association. The corresponding calculation formula is:
Ce_Word[word,i]x i >θ;
wherein word represents a word; i is the column coordinates in the spatial position encoding vector of the word; x is x i Is the encoded value of the reference convolution operation.
By the filtering operation, the significant features W in the vector are encoded by the spatial position i Obtaining an input word vector X of a feedforward neural network i
In the word space fusion model according to the embodiment of the invention, a feedforward neural network comprises an input layer, a hidden layer and an output layer; wherein there is only one hidden layer.
Specifically, text description information of spatial data is expressed as a set of spatial position coding vectors of words according to vectors output by a one-dimensional convolution layer, one word is randomly removed as tag data, and the rest vectors are input into a feedforward neural network for training.
For example, a plurality of spatial position coding vectors of words of 'central restaurant, meal, good, eating' are obtained through the processing of a one-dimensional convolution layer; then the word of 'meal' is randomly removed, the Z-order code of the word of 'meal' is used as the output result of the feedforward neural network, the spatial position code vectors of other residual words are input into the network for learning, and the word of 'meal' is predicted by the other residual words. Through this training process, associations between the word "meal" and other input words, including associations of text and spatial locations, can be learned.
In order to be able to build a close association of words and spatial locations, the output layer of the word-space fusion model is adapted compared to the existing word2vec model. The output layer will not use huffman tree coding of word2vec model, but use coding based on spatial inverted index, build a spatial index for each word, and the index contains only Z-order coding of leaf nodes.
For example, the example of the word "restaurant" described in the foregoing embodiment, the spatial index created for the word based on the encoding of the spatial inverted index is expressed in the following manner:
RVec <Restaurant and restaurant> =<0,9,12>。
Through training of the feedforward neural network, links among words and spatial positions, the same word and different spatial positions are established, and the weight matrix of the hidden layer is the result according to the thought of word2 vec.
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. First, let the objective function δ of the feedforward neural network be:
where w is the word sought, which belongs to the word set t, i is the coding index of the spatial inverted index, l w A value of 1 subtracted from the length of the spatial inverted index code; sigma in the formula is a maximum likelihood function for spatial coding of the output layer, its shapeThe formula is as follows:
as shown in the above formula, d is calculated by adopting the thought of word2vec maximum likelihood function i w To describe the spatial characteristics and prevent negative values, the present scheme maps Z-order encoded values into [0,1 ] using a sigmod function]Thereby maintaining the difference of the space positions;the output result of the middle hidden layer is also an object to be optimized; />The code sub-vector representing word w, i.e<0>,<0,9>,<0,9,12>The method comprises the steps of carrying out a first treatment on the surface of the With these parameters, the value of the maximum likelihood function can be calculated.
The τ function in the objective function is used for calculating the ratio of the size of the region corresponding to the word to the size of the total region and is used as a weight parameter for adjusting the maximum likelihood function value, if the ratio is larger, the region influence of the explanatory word is larger, and the more accurate result is needed to be obtained by further optimization, wherein the calculation formula is as follows:
wherein the method comprises the steps ofIs the area of the i region to which the word w belongs, and +.>Is the sum of all areas containing the word w.
Through the description of the objective function calculation formula, the objective function fuses 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 objective function is provided, the objective function reaches the maximum value by adjusting the parameter weight of the hidden layer node by using a random gradient ascending method, and when the objective function reaches the maximum value, the weight of the middle hidden layer in the word space fusion model is the vector after the required 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 post-space fusion vector.
The process of establishing accurate connection between words and position information in spatial data is further described below in connection with the word space fusion model provided by the embodiment of the present invention.
And S21, carrying out convolution operation on the spatial position coding vector corresponding to the word by utilizing a one-dimensional convolution layer in the word space fusion model, thereby extracting the effective characteristics in the spatial position coding vector corresponding to the word, and establishing the association of the same word in different spatial subregions.
As an optional implementation manner, in step S21, filtering operation is further performed on the result of the convolution operation, so as to eliminate noise, and remove the influence of the space subarea with low influence on word space position association.
And S22, constructing a label of the feedforward neural network according to the spatial position coding vector corresponding to the word, namely generating an inverted quadtree code of each word.
Step S23, initializing a feedforward neural network in the word space fusion model, wherein the step comprises initializing a weight matrix of each layer of nodes in the feedforward neural network, and setting inverted quadtree codes of the word at corresponding output layer positions according to the word predicted by an input layer of the feedforward neural network.
Step S24, training the feedforward neural network, and optimizing the weight parameters by using the objective function.
In this step, the output result of step S21 is used as training data of the feedforward neural network.
And S25, after the objective function reaches the maximum value, training is finished, and the weight matrix of the middle hidden layer of the feedforward neural network is used as a vector after word space fusion and is output.
The query method provided by the embodiment of the invention realizes the accurate association between the words and the space positions in the space data through the word space fusion model.
Based on any of the foregoing embodiments, in an embodiment of the present invention, the step S3 specifically includes:
gathering the space subareas through a convolution layer part of the space attention model, and replacing words in the gathered space subareas with space fusion vectors of the words; the convolution layer part of the spatial attention model comprises a plurality of convolution layers which are stacked in sequence, and the convolution layers are used for realizing aggregation of the spatial subregions and association between the aggregated spatial subregions and the word sets;
inputting the spatially fused vectors of the words in the aggregated spatial subregions into a spatial attention layer part of the spatial attention model, and calculating the spatial attention value of the words by combining the spatial attention layer part with the spatial attention vector of the words to obtain the spatial attention vector of the words; 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 the spatial position in the spatially fused vector of words in the clustered spatial sub-regions.
In the previous step S2, the word space fusion model achieves an accurate association between words in the spatial data and the spatial position. In order to focus on the influence of the location information on the vector corresponding to the word, in the embodiment of the present invention, a Spatial-Attention (Spatial-Attention) model is employed.
FIG. 4 is a schematic diagram of a spatial attention model, as shown in FIG. 4, including two parts, a first part being a convolution layer and a second part being a spatial attention layer.
The convolution layer portion of the spatial attention model includes a plurality of convolution layers that are stacked in sequence. The function of the convolutional layer part is mainly to construct training input data of the spatial attention layer. Specifically, a convolution kernel function is used in a convolution layer to aggregate a plurality of areas, a text set after the aggregated areas is extracted, and the text set is used as an input of a spatial attention layer.
The convolution layer is selected in the spatial attention model because the convolution layer can furthest correlate different spatial subareas, and the spatial correlation of words is ensured not to be missed. Taking fig. 2 as an example, the adjacent subareas of the subareas 10 in fig. 2 comprise subareas 8, 9 and 11, while the adjacent subareas of the subareas 9 are subareas 0, 8, 10, 11, 12 and 6, only the relation from subarea 8 to subarea 10, 9 and 11 can be established by means of subarea 10, but the relation between subarea 8 and subarea 0, 11, 12 and 6 can be additionally established by means of subarea 9.
The convolution layer portion uses a multi-layer convolution stack to expand the range of sub-region associations. The convolution is in continuous dimension reduction, a certain range of areas can be covered by the convolution operation of one convolution layer, and the convolution operation can be carried out in a wider area after the subsequent convolution layer, so that wider association is established, and a more accurate word space association can be identified by the space attention layer during operation.
FIG. 5 is a flow chart of operations to be performed by a convolution layer in a spatial attention model, as shown in FIG. 5, including:
and S31, taking the space region divided by the quadtree and the sample space data as input of a convolution layer, and setting a convolution kernel function according to the space region divided by the quadtree.
Since quadtree partitioning tends to be irregular, a maximum of 8 sub-regions adjacent around each sub-region, regardless of size, are included in the window of the convolution kernel, centered around that sub-region, forming an irregular convolution kernel. For example, centered on sub-region 0 in fig. 2, the kernel window includes sub-regions numbered 0, 4, 6, 8, 9, and 12.
Step S32, preprocessing the spatial data, where the preprocessing includes: 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.
Step S33, scanning the space subareas divided by the quadtree line by line in the order 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 subareas.
Different from a general convolution calculation method, the convolution operation in the step calculates the Z-order code of the space subarea, and the maximum nine subareas (the currently scanned subarea and the maximum 8 adjacent subareas) are mapped into a new space subarea through the convolution operation, wherein the new space subarea is the aggregated space subarea.
And step S34, constructing a word set of the aggregated space subareas according to the convolution operation result.
According to the window of the convolution kernel function set in the step S31, words of the spatial data of all the spatial subregions in the window can be extracted, the words are combined into a word set, and the word set is associated with the aggregated subregions calculated in the step S33, so that the word set of the aggregated subregions is obtained.
Step S35, the aggregated space subarea and the word set of the aggregated space subarea are used as the input of the input or output layer of the next convolution layer.
Since there are multiple convolutional layers, if there are more convolutional layers after the current convolutional layer, the aggregated sub-region and the word set with 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 one, the aggregated sub-region and the word set with the aggregated sub-region generated by the current convolutional layer can be used as the input of the output layer.
Step S36, judging whether the operation of the convolution layer is finished, if not, executing step S32 to calculate the next convolution layer, otherwise executing step S37.
In this step, whether the operation of the convolution layer is ended or not is determined according to the preset convolution layer number.
Step S37, the words in the word set corresponding to the current space subarea are converted into space fusion vectors generated by the word space fusion model, then a matrix related to the current space subarea is output, and the set of the space fusion vectors corresponding to each current space subarea in the matrix is input into a space Attention (Spatial-Attention) layer as a whole text.
In the previous step, the aggregation of the spatial sub-regions is achieved by a convolutional layer. In this step, the current spatial subregion is a spatial subregion that has been aggregated several times, and the word set of the current spatial subregion is a set constructed from words in the aggregated spatial subregion.
The words in the word set corresponding to the current space subarea are converted into the space fusion post-vectors corresponding to the words, which are generated by the previous word space fusion model, so that an input matrix A can be formed by the vectors m Where m is the corresponding sub-region code.
The vector set after spatial fusion corresponding to the current space subarea is used as a whole text to be input into the space attention layer, so that the maximum realization can be realized
Spatial location association of words.
The spatial attention layer part of the spatial attention model is stacked with a plurality of spatial attention layers for highlighting the influence of the spatial position in the word vector corresponding to the word, thereby encoding a more accurate word vector of the fused position information.
Fig. 6 is a schematic structural diagram of a spatial attention layer, as shown in fig. 6, where the spatial attention layer is different from the attention layer commonly used in the prior art mainly in two points: first, the input of the spatial Attention layer is not a sentence or a paragraph, but a set of word vectors corresponding to the words calculated in the convolution layer part is used as the raw material for the Attention calculation, A in the figure 1 m I.e. representing the spatial region A m The first row of the corresponding matrix, i.e. the vector of the first word, is done so as to take into account the association of words within a certain spatial rangeSex. Second, a spatial influence matrix is introduced in calculating an Attention (Attention) value, so that position information can be focused in the calculation of the Attention value. Wherein, the calculation formula of the attention value is as follows:
wherein the preceding bracket of the formulaIs the attention calculating method in the prior art, and the latter one in parentheses of the formula +.>The weight parameters are constructed by using word space to influence the moment array, wherein word refers to the word corresponding to the current node, namely word is the word input by the node, and i is the vector index.
From the above equation, it can be seen that the larger the spatial influence is, the larger the weight coefficient is, the smaller the spatial influence is, the weight coefficient is smaller, and the spatial influence coefficient is minimum when 0, so that the value of the Attention weight with the spatial influence, namely alpha, can be amplified by this operation i And simultaneously, the value of the Attention weight without space influence is reduced, so that the Attention to the position information is achieved.
Since different subregions may have the same word, after the text data of each subregion is calculated, 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 related to a query method provided in an embodiment of the present invention, as shown in fig. 7, each Spatial-Attention layer performs Attention calculation of each Spatial sub-region, and finally, the calculation results are summarized to the word vector merging layer, and after the vectors of the same word are added and summed to obtain a result, the result is used as input of the next Spatial-Attention layer to perform the same operation, and the loop is repeated 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, including:
step S301, receiving an output result of the convolution layer, initializing a space attention layer, including initializing three weight matrixes q, k and v, and loading a space influence matrix.
Step S302, performing data formatting processing, mainly including: and extracting word vectors of words corresponding to the space subareas, and taking the word vectors as input of the space attention layer.
Step S303, carrying out space attention operation on words one by one, calculating corresponding attention values, and forming an output word vector.
In this step, the spatial attention calculation for the word may be performed with reference to the attention value calculation formula described above.
And step S304, summarizing the calculation results of all the subareas, adding and summing the vectors of the same words, and outputting the sum as the calculation result of the current spatial attention layer.
Step S305, judging whether all the spatial attention layers are calculated, if yes, turning to step S306, otherwise, taking the output of the layer as the input of the next spatial attention layer, and re-executing step S302.
In this step, whether the calculation of the spatial attention layer is finished or not is determined according to the preset spatial attention layer number.
Step S306, outputting the calculated word vector, wherein the word vector is subjected to space attention operation, and the influence of the effective space position is amplified.
In the embodiment of the invention, the word vector finally output by the spatial attention model is called a spatial attention vector.
The query method provided by the embodiment of the invention amplifies the influence of the position information in the spatial attention vector of the word through the attention mechanism.
Based on any of the foregoing embodiments, in an embodiment of the present invention, the step S4 specifically includes:
taking the spatial attention vector of the word, the influence vector of the word and the region vector of the word as input data of a BERT model, training a Mask LM task on the BERT model, and outputting a word spatial association vector for reflecting association between the word and a spatial region by the BERT model after the Mask LM task training is finished;
setting a first label for words in a preset space subarea set according to the word space relevance vector, randomly selecting words in the preset space subarea according to a preset proportion, replacing the selected words with words outside the preset space subarea set, and setting a second label for the replaced words; randomly selecting two words in the preset space subarea, determining a CLS mark of a word vector according to a comparison result, and finally inputting the BERT model, wherein the BERT model outputs a word embedding vector; wherein,
The preset space subarea set is a set of the preset space subarea and adjacent space subareas thereof.
After the spatial attention operation is completed, the BERT (Bidirectional Encoder Representations from Transformers) pre-training model is used for encoding word vectors, and the association of words and spatial positions can be more comprehensively established through the bi-directional transducer connection mechanism of the BERT, because the BERT model can read complete context information of the whole text during training.
Fig. 9 is a schematic structural diagram of a BERT model used in the embodiment of the present invention, and as shown in fig. 9, the BERT model is divided into 3 parts, namely an input layer, a transform coding layer and an output layer.
The BERT model in the prior art is trained only for texts, so that the input data of the input layer is formed by adding word vectors, word position vectors and marking vectors of texts to which the words belong. In the embodiment of the invention, the BERT model needs to learn the implicit semantics of the position information, so that the input data of the BERT model input layer comprises word vectors, influence vectors of words and region vectors of words. Fig. 10 is a schematic diagram of input data of the BERT model input layer. The term vector refers to the space contained by the space Attention (Spatial-Attention) model The vector of position-related information, the aforementioned spatial attention vector. E in word vector [cls] And E is [seq] Representing the beginning and ending marks of the phrase sequence, respectively, i.e. the words between the two marks belong to the same sentence. The term influence vector refers to a vector capable of distinguishing the spatial influence sensitivity degree of a term, and the vector can be generated from the spatial attention vector of the term and the spatial influence vector of the term. The term region vector refers to the code vector corresponding to the sub-space region divided by the quadtree, for example, the term region vector E A And the coding vector of the subspace area A after the quadtree division is represented.
In the embodiment of the invention, the region vector is used for replacing the marking 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 the word, the spatial attention vector E is used i By multiplying the calculation mode of the inner product of the space influence vector corresponding to the word, the space influence sensitive words and the non-sensitive words can be effectively distinguished, and the calculation formula is as follows:
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 trained through the task, and because the input word vectors are coded by the spatial meaning force model and already contain the relevant information of the spatial positions, the codes output by the Mask LM task are the code 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 vector.
However, excessive interpretation of semantics may occur in the Mask LM task, and words with very small spatial relevance are learned as words with very strong spatial relevance, so that, for this problem, the embodiment of the present invention weakens irrelevant word spatial relevance by performing BERT training task-Spatial Text Prediction (spatial text prediction) -for spatial location. FIG. 11 is a flow chart for weakening irrelevant word spatial associations by spatial text prediction tasks in the BERT model, as shown in FIG. 11, comprising the steps of:
step S41, using a word space association vector generated by the BERT model as input, scanning sub-space regions divided by the quadtree line by line, taking each sub-space region as a center, and selecting at most 8 sub-regions adjacent to each sub-space region as a basic unit of task calculation.
The operation of this step is similar to that done by the convolution layer in the spatial attention model and therefore will not be repeated here.
Step S42, labeling all words in each sub-region in the selected region to indicate that the words belong to the same region.
Step S43, randomly selecting a certain proportion of words from the word set corresponding to the subareas for replacement, replacing the words with words in the subarea set with a longer distance, and marking tags to indicate that the words and the original words in the subareas do not belong to the same subarea.
In the embodiment of the present invention, the proportion of the randomly selected words may be 30%, and in other embodiments of the present invention, other proportion values may also be used.
Step S44, carrying out random pairwise combination on words in the same subarea, if the two selected words are from the subarea, filling 0 in the CLS mark of the word vector, otherwise filling 1, and inputting the words into the BERT model for encoding.
In this step, it is considered that the relevance of words in the far-away space subregion should be low, so that words in the far-away space subregion are used and marked as not related to the words in the current subregion, or in order to reduce the word-space relevance by utilizing the characteristic that the space position is far away, and reduce the occurrence probability of the space relevance overstock.
The word vector output by the BERT model in step S45 is the word embedding vector to be obtained.
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 foregoing embodiments, fig. 12 is a schematic diagram of a query device provided by an embodiment of the present invention, where, as shown in fig. 12, the query device provided by the embodiment of the present invention includes:
a space region determining module 1201, configured to determine a space region corresponding to a query request according to location information when a user initiates the query request;
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 mapping relationship between a preset word and a word embedding vector, 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; 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 according to the text description information or word embedding vectors of words contained in the candidate query results;
and the distance calculating and sorting module 1204 is configured to sort and return 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.
When the query device provided by the embodiment of the invention is used for carrying out query operation, the candidate result set in the specific space area 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. The query result is more accurate because the location information is added instead of just the text information during the query.
Fig. 13 is a schematic diagram of an entity structure of an electronic device related to a query method according to an embodiment of the present invention, where, as shown in fig. 13, the electronic device may include: processor 1310, communication interface (Communications Interface) 1320, memory 1330 and communication bus 1340, wherein processor 1310, communication interface 1320, memory 1330 communicate with each other via communication bus 1340. Processor 1310 may call logic instructions in memory 1330 to perform the following method: determining a space region corresponding to a query request according to position information when a 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; according to a preset mapping relation between words and word embedding vectors, determining feature vectors 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 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 according to the text description information or word embedding vectors of words contained in the candidate query results; and sequencing and returning each candidate query result in the candidate query result set to a 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.
It should be noted that, in this embodiment, the electronic device may be a server, a PC, or other devices in the specific implementation, so long as the structure of the electronic device includes the processor 1310, the communication interface 1320, the memory 1330, and the communication bus 1340 as shown in fig. 13, where the processor 1310, the communication interface 1320, and the memory 1330 perform communication with each other through the communication bus 1340, and the processor 1310 may call logic instructions in the memory 1330 to execute the above method. The embodiment does not limit a specific implementation form of the electronic device.
Further, the logic instructions in the memory 1330 can be implemented in the form of software functional units and can be stored in a computer readable storage medium when sold or used as a stand alone product. Based on this understanding, the technical solution of the present invention may be embodied essentially or in a part contributing to the prior art or in a part of the technical solution, in the form of a software product stored in a storage medium, comprising several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) 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, random Access Memory), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
Further, embodiments of the present invention disclose a computer program product comprising a computer program stored on a non-transitory computer readable storage medium, the computer program comprising program instructions which, when executed by a computer, enable the computer to perform the methods provided by the above-described method embodiments, for example comprising: determining a space region corresponding to a query request according to position information when a 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; according to a preset mapping relation between words and word embedding vectors, determining feature vectors 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 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 according to the text description information or word embedding vectors of words contained in the candidate query results; and sequencing each candidate query result in the candidate query result set 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, and returning the sequencing result to the user.
In another aspect, embodiments of the present invention also provide a non-transitory computer readable storage medium having stored thereon a computer program, which when executed by a processor is implemented to perform the method provided in the above embodiments, for example, including: determining a space region corresponding to a query request according to position information when a 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; according to a preset mapping relation between words and word embedding vectors, determining feature vectors 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 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 according to the text description information or word embedding vectors of words contained in the candidate query results; and sequencing and returning each candidate query result in the candidate query result set to a 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 apparatus embodiments described above are merely illustrative, wherein the elements illustrated as separate elements may or may not be physically separate, and the elements shown as elements may or may not be physical elements, may be located in one place, or may be distributed over a plurality of network elements. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art will understand and implement the present invention without undue burden.
From the above description of embodiments, it will be apparent to those skilled in the art that the embodiments may be implemented by means of software plus necessary general hardware platforms, but may also be implemented by means of hardware. Based on this understanding, the foregoing technical solution may be embodied essentially or in part in the form of a software product, which may be stored in a computer readable storage medium, such as a ROM/RAM, a magnetic disk, an optical disk, etc., including several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to perform the embodiments or some parts of the methods described in the embodiments.
Finally, it should be noted that: the above embodiments are only for illustrating the technical solution of the present invention, and are not limiting; although the 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 scheme described in the foregoing embodiments can be modified or some of the technical features can be replaced equivalently; such modifications and substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims (8)

1. A method of querying, comprising:
determining a space region corresponding to a query request according to position information when a user initiates the query request, wherein the division of the space region is preset, and comparing the position information of the query request with the division result of the space region according to the division result of the set space region to determine the space region corresponding to 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;
according to a preset mapping relation between words and word embedding vectors, determining feature vectors 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 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 according to the text description information or word embedding vectors of words contained in the candidate query results;
Ordering and returning each candidate query result in the candidate query result set to a 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;
before the step of determining the space region corresponding to the query request according to the position information when the user initiates the query request, the method further comprises the following steps:
acquiring sample space data, wherein the sample space data comprises position information and text description information;
combining the position information, and determining a space subarea where the word is located for each word in the text description information in a quadtree division mode; according to the space subarea where each word in the text description information is located, obtaining a space position coding vector and a space influence vector corresponding to each word; wherein the space subarea is the result of index space segmentation;
according to the spatial position coding vector and the spatial influence vector of each word in the text description information, carrying out spatial fusion on each word in the text description information to obtain a spatial fusion post-vector containing the association degree of the word and different spatial subregions;
Aggregating the space subareas, and replacing words in the aggregated space subareas with space fusion vectors of the words; according to the space fusion post-vectors of the words in the collected space subareas and the space influence vectors of the words, calculating the space attention value of the words to obtain the space attention vectors of the words; the spatial attention vector is used for highlighting the influence of the spatial position;
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; wherein the influence vector of the word is generated by the spatial attention vector of the word and the spatial influence vector of the word; the regional vector of the word refers to the coding vector corresponding to the subspace region divided by the quadtree;
and establishing a mapping relation between the words and the corresponding word embedding vectors.
2. The query method according to claim 1, wherein the spatial fusion is performed 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 fused vector containing the association degrees of the word and different spatial sub-regions, and the method specifically comprises:
Inputting the spatial position coding vector and the spatial influence vector of each word in the text description information into a word spatial fusion model to obtain a spatial fusion post-vector of each word in the text description information; wherein,
the word space fusion model comprises a one-dimensional convolution layer and a feedforward neural network; wherein,
the one-dimensional convolution layer extracts effective features in the spatial position coding vector through a convolution kernel function, and eliminates a spatial subarea with the spatial influence lower than a preset threshold according to the spatial influence vector;
the feedforward neural network comprises an input layer, a hidden layer and an output layer, wherein only one hidden layer exists, and the output layer sets inverted quadtree codes of first words for the first words to be predicted by the input layer; and the objective function of the feedforward neural network is used for realizing fusion judgment of the position information and the text description information.
3. The query method according to claim 2, wherein the aggregating the space subregions, and replacing the word in the aggregated space subregion with the space fusion vector of the word, specifically comprises:
gathering the space subareas through a convolution layer part of the space attention model, and replacing words in the gathered space subareas with space fusion vectors of the words; the convolution layer part of the spatial attention model comprises a plurality of convolution layers which are stacked in sequence, and the convolution layers are used for realizing aggregation of the spatial subregions and association between the aggregated spatial subregions and the word sets;
Correspondingly, the calculating the spatial attention value of the word according to the spatial fusion post-vector of the word in the collected spatial subarea and the spatial influence vector of the word to obtain the spatial attention vector of the word specifically comprises the following steps:
inputting the spatially fused vectors of the words in the aggregated spatial subregions into a spatial attention layer part of the spatial attention model, and calculating the spatial attention value of the word by combining the spatial attention layer part with the spatial attention vector of the word to obtain the spatial 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 the spatial position in the spatially fused vector of words in the clustered spatial sub-regions.
4. The query method according to claim 1, wherein the 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 spatial attention vector of the word, the influence vector of the word and the region vector of the word as input data of a BERT model, training a Mask LM task on the BERT model, and outputting a word spatial association degree vector for reflecting association degree between the word and a spatial region by the BERT model after the Mask LM task training is finished;
Setting a first label for words in a preset space subarea set according to the word space relevance vector, randomly selecting words in the preset space subarea according to a preset proportion, replacing the selected words with words outside the preset space subarea set, and setting a second label for the replaced words; randomly selecting two words in the preset space subarea, determining a CLS mark of a word vector according to a comparison result, and finally inputting the BERT model, wherein the BERT model outputs a word embedding vector; wherein,
the preset space subarea set is a set of the preset space subarea and adjacent space subareas thereof.
5. The query method according to claim 1, wherein the determining the feature vector of the text description information of the query request and the feature vector of each candidate query result in the candidate query result set according to the preset mapping relationship between the word and the word embedding vector specifically includes:
word segmentation operation is carried out on the text description information of the query request, corresponding word embedding vectors are determined for words in the text description information obtained through the word segmentation operation according to a preset mapping relation between words and word embedding vectors, and feature vectors of the text description information are determined 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 the 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.
6. A query device, comprising:
the space region determining module is used for determining a space region corresponding to the query request according to the position information when the user initiates the query request;
the candidate query result set determining module is used for 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;
the feature vector determining module is used for determining feature vectors 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 relation between words and word embedding vectors; 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 according to the text description information or word embedding vectors of words contained in the candidate query results;
The distance calculating and sorting module is used for sorting the candidate query results in the candidate query result set according to the distance between the feature vector of the candidate query result in the candidate query result set and the feature vector of the text description information of the query request, and returning the sorted candidate query result to the user;
before the step of determining the space region corresponding to the query request according to the position information when the user initiates the query request, the method further comprises the following steps:
acquiring sample space data, wherein the sample space data comprises position information and text description information;
combining the position information, and determining a space subarea where the word is located for each word in the text description information in a quadtree division mode; according to the space subarea where each word in the text description information is located, obtaining a space position coding vector and a space influence vector corresponding to each word; wherein the space subarea is the result of index space segmentation;
according to the spatial position coding vector and the spatial influence vector of each word in the text description information, carrying out spatial fusion on each word in the text description information to obtain a spatial fusion post-vector containing the association degree of the word and different spatial subregions;
Aggregating the space subareas, and replacing words in the aggregated space subareas with space fusion vectors of the words; according to the space fusion post-vectors of the words in the collected space subareas and the space influence vectors of the words, calculating the space attention value of the words to obtain the space attention vectors of the words; the spatial attention vector is used for highlighting the influence of the spatial position;
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; wherein the influence vector of the word is generated by the spatial attention vector of the word and the spatial influence vector of the word; the regional vector of the word refers to the coding vector corresponding to the subspace region divided by the quadtree;
and establishing a mapping relation between the words and the corresponding word embedding vectors.
7. 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 processor implements the steps of the querying method as claimed in any one of claims 1 to 5 when executing the program.
8. A non-transitory computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the steps of the query method of any of claims 1 to 5.
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 CN112632406A (en) 2021-04-09
CN112632406B true 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)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115408568B (en) * 2021-05-26 2024-04-05 中科寒武纪科技股份有限公司 Method for fusing operators of neural network and related products
CN116108072B (en) * 2023-04-04 2023-09-19 阿里巴巴(中国)有限公司 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
一种地理信息检索的定性模型;高勇;姜丹;刘磊;林星;邬伦;;北京大学学报(自然科学版);20160331;第52卷(第02期);全文 *

Also Published As

Publication number Publication date
CN112632406A (en) 2021-04-09

Similar Documents

Publication Publication Date Title
CN111753060B (en) Information retrieval method, apparatus, device and computer readable storage medium
CN109918532B (en) Image retrieval method, device, equipment and computer readable storage medium
CN110795543A (en) Unstructured data extraction method and device based on deep learning and storage medium
CN111639171A (en) Knowledge graph question-answering method and device
CN113434623B (en) Fusion method based on multi-source heterogeneous space planning data
CN110309192A (en) It is matched using the structured data of neural network encoder
CN112632406B (en) Query method, query device, electronic equipment and storage medium
CN110929080A (en) Optical remote sensing image retrieval method based on attention and generation countermeasure network
CN112417381B (en) Method and device for rapidly positioning infringement image applied to image copyright protection
CN110928961A (en) Multi-mode entity linking method, equipment and computer readable storage medium
CN116151263B (en) Multi-mode named entity recognition method, device, equipment and storage medium
CN114444507A (en) Context parameter Chinese entity prediction method based on water environment knowledge map enhancement relationship
CN109829065A (en) Image search method, device, equipment and computer readable storage medium
CN111143507A (en) Reading understanding method based on composite problems
CN111723306A (en) Sequence position recommendation method based on geographical perception
CN112579816B (en) Remote sensing image retrieval method and device, electronic equipment and storage medium
CN115797795B (en) Remote sensing image question-answer type retrieval system and method based on reinforcement learning
CN113032567B (en) Position embedding interpretation method and device, computer equipment and storage medium
CN112948717B (en) Massive space POI searching method and system based on multi-factor constraint
CN112507912A (en) Method and device for identifying illegal picture
CN112579813A (en) Remote sensing image retrieval method and device based on knowledge graph
CN116860952B (en) RPA intelligent response processing method and system based on artificial intelligence
Heras et al. Searching and Mining Large Collections of Geospatial Data (GeoSearch 2023) Nov. 13, 2023, Hamburg, Germany
CN116127977B (en) Casualties extraction method for referee document
WO2022066239A1 (en) Representation learning of semi-structured data

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