<jupyter_start><jupyter_text>Sentiment classification<jupyter_code>import torch

from perceiver.data import TextPreprocessor
from perceiver.model import LitTextClassifier
imdb_preproc = TextPreprocessor(tokenizer_path='../.cache/imdb-tokenizer-10003.json')
# Download model checkpoints
!wget -nc -O logs.zip https://martin-krasser.com/perceiver/logs-update-2.zip
!unzip -qo logs.zip
ckpt_path = 'logs/seq_clf/version_1/checkpoints/epoch=021-val_loss=0.253.ckpt'

model = LitTextClassifier.load_from_checkpoint(ckpt_path, clf_ckpt=None).model
model.eval();
text_batch = [
    "I've seen this movie yesterday and it was really boring",
    "I can recommend this movie to all fantasy movie lovers"
]
with torch.no_grad():
    logits = model(*imdb_preproc.preprocess_batch(text_batch))
    preds = logits.argmax(dim=1)
for text, pred in zip(text_batch, preds):
    print(f'{text} (positive = {pred == 1})')<jupyter_output>I've seen this movie yesterday and it was really boring (positive = False)
I can recommend this movie to all fantasy movie lovers (positive = True)
{'fraction_non_alphanumeric': 0.107981220657277, 'fraction_numerical': 0.015023474178403756, 'mean_word_length': 5.580246913580247, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '124905', 'license': 'Apache-2.0', 'n_tokens_mistral': 369, 'n_tokens_neox': 356, 'n_words': 90, 'path': 'notebooks/txt-clf.ipynb', 'repo_name': 'usryokousha/perceiver-io', 'size': '1065'}