Как эффективно выполнять итерации при встраивании длинных предложений?

#google-colaboratory #huggingface-transformers

Вопрос:

Я использую LongformerModel для получения длинных предложений. Я не хочу сокращать свои абзацы. Вот мой код: примечание: corpus_all-это список абзацев, где длина каждого абзаца варьируется от 100 до 2500.

 emb_of_cor=[] for i in range(len(corpus_all)):  input_ids = torch.tensor(tokenizer.encode(corpus_all[i])).unsqueeze(0)  # batch of size 1   attention_mask = torch.ones(input_ids.shape, dtype=torch.long, device=input_ids.device) # initialize to local attention  global_attention_mask = torch.zeros(input_ids.shape, dtype=torch.long, device=input_ids.device) # initialize to global attention to be deactivated for all tokens  global_attention_mask[:, [1, 4, 21,]] = 1 # Set global attention to random tokens for the sake of this example  # Usually, set global attention based on the task. For example,  # classification: the lt;sgt; token  # QA: question tokens  # LM: potentially on the beginning of sentences and paragraphs  outputs = model(input_ids, attention_mask=attention_mask, global_attention_mask=global_attention_mask)  sequence_output = outputs.last_hidden_state  pooled_output = outputs.pooler_output  emb_of_cor.append(pooled_output)  

Когда я запускаю этот код, потребовалось много оперативной памяти, и collab перезапускается. В чем проблема? Такого рода проблемы у меня возникают, когда я пытаюсь использовать 'sentence-transformers/distilbert-base-nli-stsb-mean-tokens' max_length 512.