distil icon indicating copy to clipboard operation
distil copied to clipboard

add nlp examples

Open junaidahmed361 opened this issue 3 years ago • 1 comments

Can you include examples of nlp applications, including the use of HuggingFace transformers?

junaidahmed361 avatar Oct 08 '21 04:10 junaidahmed361

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.

Anurich avatar Dec 23 '21 11:12 Anurich

We have added additional support for NLP models, which commonly use dict-style inputs. An example notebook is given in the tutorials folder.

nab170130 avatar Feb 04 '23 08:02 nab170130