distil
distil copied to clipboard
add nlp examples
Can you include examples of nlp applications, including the use of HuggingFace transformers?
class model_wrapper(torch.nn.Module):
def __init__(self):
super().__init__()
self.model = AutoModelForSequenceClassification.from_pretrained("roberta-base", output_hidden_states = True)
self.model.to(device)
self.embedding_dim = 768
def forward(self,x, last=False):
if last:
outputs = self.model(x["input_ids"].squeeze().to(device), attention_mask=x["attention_mask"].squeeze().to(device))
embedding = torch.mean(outputs.hidden_states[-1], dim=1).squeeze()
return outputs, embedding
def get_embedding_dim(self):
return self.embedding_dim
I think you just have to include the Model Wrapper and then you can simply call the functions available in the library.
We have added additional support for NLP models, which commonly use dict-style inputs. An example notebook is given in the tutorials folder.