MCPcopy Create free account
hub / github.com/google-research/language / featurize_query

Method featurize_query

language/realm/featurization.py:166–188  ·  view source on GitHub ↗

Featurizes a Query. Args: query: a Query instance. fmt: can be either 'dict' or 'bert_inputs'. Default is 'dict'. Returns: If fmt is 'dict', a dict with the following structure: input_ids: [query_seq_len] int32 Tensor input_mask: [query_seq_len] int32 Tens

(self, query, fmt='dict')

Source from the content-addressed store, hash-verified

164
165 @profile.profiled_function
166 def featurize_query(self, query, fmt='dict'):
167 """Featurizes a Query.
168
169 Args:
170 query: a Query instance.
171 fmt: can be either 'dict' or 'bert_inputs'. Default is 'dict'.
172
173 Returns:
174 If fmt is 'dict', a dict with the following structure:
175 input_ids: [query_seq_len] int32 Tensor
176 input_mask: [query_seq_len] int32 Tensor
177 segment_ids: [query_seq_len] int32 Tensor
178 If fmt is 'bert_inputs', a BertInputs object.
179 """
180 query_mask_features = self.mask_query(query)
181
182 bert_inputs = bert_format(
183 input_seqs=[query_mask_features['token_ids_after_masking']],
184 max_seq_len=self.query_seq_len,
185 cls_id=self.tokenizer.cls_id,
186 sep_id=self.tokenizer.sep_id)
187
188 return self._reformat_bert_inputs(bert_inputs, fmt)
189
190 @profile.profiled_function
191 def featurize_document(self, doc, fmt='dict'):

Callers 2

embedMethod · 0.80

Calls 3

mask_queryMethod · 0.95
_reformat_bert_inputsMethod · 0.95
bert_formatFunction · 0.85

Tested by

no test coverage detected