🚀 ポーランド語によるセンチメント分類
このプロジェクトは、ポーランド語のテキストに対するセンチメント分類を行うものです。Transformerモデルを利用して、ネガティブ、中立、ポジティブの3つのセンチメントを識別します。
🚀 クイックスタート
以下のコードを実行することで、ポーランド語のテキストに対するセンチメント分類を行うことができます。
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")
input = ["Ale fajnie, spadł dzisiaj śnieg! Ulepimy dziś bałwana?"]
encoding = tokenizer(
input,
add_special_tokens=True,
return_token_type_ids=True,
truncation=True,
padding='max_length',
return_attention_mask=True,
return_tensors='pt',
)
output = model(**encoding).logits.to("cpu").detach().numpy()
prediction = id2label[np.argmax(output)]
print(input, "--->", prediction)
予測結果の例:
['Ale fajnie, spadł dzisiaj śnieg! Ulepimy dziś bałwana?'] ---> positive
💻 使用例
基本的な使用法
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")
input = ["Ale fajnie, spadł dzisiaj śnieg! Ulepimy dziś bałwana?"]
encoding = tokenizer(
input,
add_special_tokens=True,
return_token_type_ids=True,
truncation=True,
padding='max_length',
return_attention_mask=True,
return_tensors='pt',
)
output = model(**encoding).logits.to("cpu").detach().numpy()
prediction = id2label[np.argmax(output)]
print(input, "--->", prediction)
高度な使用法
input_texts = ["Tekst pierwszy", "Tekst drugi", "Tekst trzeci"]
encodings = tokenizer(
input_texts,
add_special_tokens=True,
return_token_type_ids=True,
truncation=True,
padding='max_length',
return_attention_mask=True,
return_tensors='pt'
)
outputs = model(**encodings).logits.to("cpu").detach().numpy()
predictions = [id2label[np.argmax(output)] for output in outputs]
for text, pred in zip(input_texts, predictions):
print(text, "--->", pred)
📚 ドキュメント
概要
📄 ライセンス
このプロジェクトは、CC BY 4.0ライセンスの下で提供されています。