Код: Выделить всё
IndexError: index out of range in self
Ниже приведен код, который я запустил:
Код: Выделить всё
pip install git+https://github.com/llefebure/dynamic_bernoulli_embeddings.git
Код: Выделить всё
import pickle
import re
import numpy as np
import pandas as pd
from dynamic_bernoulli_embeddings.analysis import DynamicEmbeddingAnalysis
from dynamic_bernoulli_embeddings.training import train_model
from nltk import word_tokenize as nltk_word_tokenize
from gensim.corpora import Dictionary
from tqdm.notebook import tqdm
tqdm.pandas()
Код: Выделить всё
def _bad_word(word):
if len(word) < 2:
return True
if any(c.isdigit() for c in word):
return True
if "/" in word:
return True
return False
def word_tokenize(text):
text = re.sub(r"co-operation", "cooperation", text)
text = re.sub(r"-", " ", text)
words = [w.lower().strip("'.") for w in nltk_word_tokenize(text)]
words = [w for w in words if not _bad_word(w)]
return words
Код: Выделить всё
dataset = pd.read_csv(".../un-general-debates.csv")
dataset["bow"] = dataset.text.progress_apply(word_tokenize)
dataset["time"] = dataset.year - dataset.year.min()
Код: Выделить всё
dictionary = Dictionary(dataset.bow)
dictionary.filter_extremes(no_below=10, no_above=1.)
dictionary.compactify()
print(len(dictionary))
Код: Выделить всё
model, loss_history = train_model(
dataset, dictionary.token2id, validation=0.1, num_epochs=6, k=100, notebook=True)
- Проверил, что набор данных загружен правильно и токенизирован, как предполагалось.
Проверил, что объект Dictionary создан правильно. - Искал похожие проблемы, связанные с «индексом вне диапазона», но не смог найти конкретного решения к динамическому внедрению слов (DWB).
Что вызывает ошибку IndexError: индекс выходит за пределы диапазона самостоятельно во время обучения?
Как устранить эту проблему ?
Будем очень признательны за любую помощь или предложения. Спасибо!
Подробнее здесь: https://stackoverflow.com/questions/792 ... dding-mode