Views
No views yet
1from transformers import ElectraForPreTraining, ElectraTokenizerFast
2import torch
3
4discriminator = ElectraForPreTraining.from_pretrained("Seznam/small-e-czech")
5tokenizer = ElectraTokenizerFast.from_pretrained("Seznam/small-e-czech")
6
7sentence = "Za hory, za doly, mé zlaté parohy"
8fake_sentence = "Za hory, za doly, kočka zlaté parohy"
9
10fake_sentence_tokens = ["[CLS]"] + tokenizer.tokenize(fake_sentence) + ["[SEP]"]
11fake_inputs = tokenizer.encode(fake_sentence, return_tensors="pt")
12outputs = discriminator(fake_inputs)
13predictions = torch.nn.Sigmoid()(outputs[0]).cpu().detach().numpy()
14
15for token in fake_sentence_tokens:
16 print("{:>7s}".format(token), end="")
17print()
18
19for prediction in predictions.squeeze():
20 print("{:7.1f}".format(prediction), end="")
21print() [CLS] za hory , za dol ##y , kočka zlaté paro ##hy [SEP]
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.8 0.3 0.2 0.1 0.0