Skip to content

Instantly share code, notes, and snippets.

@lhr0909
Created August 26, 2022 03:59
Show Gist options
  • Save lhr0909/69af69256ee3425526a5933d3e22f8f6 to your computer and use it in GitHub Desktop.
Save lhr0909/69af69256ee3425526a5933d3e22f8f6 to your computer and use it in GitHub Desktop.
DIET Classifier PyTorch Snippets
from conversational_sentence_encoder.vectorizers import SentenceEncoder
from jina import Executor, requests
from docarray import DocumentArray
class ConveRTFeaturizer(Executor):
def __init__(self, multiple_contexts=False, **kwargs):
super(ConveRTFeaturizer, self).__init__(**kwargs)
self.sentence_encoder = SentenceEncoder(multiple_contexts=multiple_contexts)
@requests
def featurize(self, docs: DocumentArray, **kwargs) -> DocumentArray:
docs.embeddings = self.sentence_encoder.encode_sentences(docs.texts)
return docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment