This is probably primitive but it works. I did it in the loop. It took six hours to classify 1.2 mln reviews, some quite long, on GPU with 16GB memory.
classifier = pipeline(“zero-shot-classification”,
model = “typeform/distilbert-base-uncased-mnli”,
device = 0
)
emo_zs_labels = list()
ind = 0
lenss = len(sentences)
while ind < lenss:
bb = ind
ee = bb+seq_len if bb+seq_len < lenss else lenss
pred = classifier(sentences[bb:ee],
candidate_labels=[“sadness”, “joy”, “love”, “anger”, “fear”, “surprise”],
)
temp_labels = [x[‘labels’][0] for x in pred]
emo_zs_labels.append(temp_labels)
ind = ee
print(ind)
I experimented with seq_len, caused CUDA out of memory for 1000 and 500, so I finally set it 100.