AgaMiko's picture
Update README.md
8c5f9f2
|
raw
history blame
1.47 kB
metadata
pipeline_tag: text-classification
widget:
  - text: >-
      Pani Katarzyno z jakiej racji moja paczka przyszła do sąsiada zamiast do
      mnie? Nie można poprawnie nadać paczki?
    example_title: Sentiment
license: cc-by-4.0
language:
  - pl
logo voicelab nlp

Sentiment Classification in Polish

import numpy as np
from transformers import AutoTokenizer, AutoModelForSequenceClassification

id2label = {0: "negative", 1: "neutral", 2: "positive"}
tokenizer = AutoTokenizer.from_pretrained("Voicelab/herbert-base-cased-sentiment")

model = AutoModelForSequenceClassification.from_pretrained("Voicelab/herbert-base-cased-sentiment")

encoding = tokenizer(
          input,
          add_special_tokens=True,
          return_token_type_ids=True,
          truncation=True,
          padding='max_length',
          return_attention_mask=True,
          return_tensors='pt',
        ).to("cuda:0")
output = model(**encoding).logits.to("cpu").detach().numpy()
prediction = id2label[np.argmax(output)]

Overview