Views
No views yet
1import torch
2from transformers import AutoTokenizer, pipeline
3
4tagger_model_name = "IlyaGusev/rubertconv_toxic_editor"
5
6device = "cuda" if torch.cuda.is_available() else "cpu"
7device_num = 0 if device == "cuda" else -1
8tagger_pipe = pipeline(
9 "token-classification",
10 model=tagger_model_name,
11 tokenizer=tagger_model_name,
12 framework="pt",
13 device=device_num,
14 aggregation_strategy="max"
15)
16
17text = "..."
18tagger_predictions = tagger_pipe([text], batch_size=1)
19sample_predictions = tagger_predictions[0]
20print(sample_predictions)