mirror of
https://github.com/modelscope/modelscope.git
synced 2026-09-01 19:49:03 +02:00
Merge pull request #676 from slin000111/master
fix embedding and inference device in faq question answering pipeline
This commit is contained in:
@@ -375,6 +375,8 @@ class ProtoNet(nn.Module):
|
||||
input_ids = torch.IntTensor(input_ids)
|
||||
if not isinstance(input_mask, Tensor):
|
||||
input_mask = torch.IntTensor(input_mask)
|
||||
input_ids = input_ids.to(self.bert.device)
|
||||
input_mask = input_mask.to(self.bert.device)
|
||||
rst = self.bert(input_ids, input_mask)
|
||||
last_hidden_states = rst.last_hidden_state
|
||||
if len(input_mask.shape) == 2:
|
||||
|
||||
@@ -50,6 +50,9 @@ class FaqQuestionAnsweringPipeline(Pipeline):
|
||||
return pipeline_parameters, pipeline_parameters, pipeline_parameters
|
||||
|
||||
def get_sentence_embedding(self, inputs, max_len=None):
|
||||
if (self.model or (self.has_multiple_models and self.models[0])):
|
||||
if not self._model_prepare:
|
||||
self.prepare_model()
|
||||
inputs = self.preprocessor.batch_encode(inputs, max_length=max_len)
|
||||
sentence_vecs = self.model.forward_sentence_embedding(inputs)
|
||||
sentence_vecs = sentence_vecs.detach().tolist()
|
||||
|
||||
Reference in New Issue
Block a user