<jupyter_start><jupyter_text>IO markup  Train<jupyter_code>from modules.data import bert_data
train_df_path = "/home/eartemov/ae/work/factRuEval-2016/dev.csv"
valid_df_path = "/home/eartemov/ae/work/factRuEval-2016/test.csv"
device = "cuda:0"
data = bert_data.LearnData.create(
    train_df_path=train_df_path,
    valid_df_path=valid_df_path,
    idx2labels_path="/home/eartemov/ae/work/factRuEval-2016/idx2labels5.txt",
    clear_cache=True,
    batch_size=8,
    device=device
)
from modules.models.bert_models import BERTBiLSTMAttnCRF
model = BERTBiLSTMAttnCRF.create(len(data.train_ds.idx2label), crf_dropout=0.3, is_freeze=False, device=device)
from modules.train.train import NerLearner
num_epochs = 100
learner = NerLearner(
    model, data, "/home/eartemov/ae/work/models/fre-BERTBiLSTMAttnCRF-fit_BERT-IO.cpt",
    t_total=num_epochs * len(data.train_dl), lr=0.0001)
model.get_n_trainable_params()
learner.fit(epochs=num_epochs)<jupyter_output><empty_output><jupyter_text>Predict<jupyter_code>from modules.data.bert_data import get_data_loader_for_predict
dl = get_data_loader_for_predict(data, df_path=data.valid_ds.config["df_path"])
preds = learner.predict(dl)
from sklearn_crfsuite.metrics import flat_classification_report
from modules.analyze_utils.utils import bert_labels2tokens, voting_choicer
from modules.analyze_utils.plot_metrics import get_bert_span_report
pred_tokens, pred_labels = bert_labels2tokens(dl, preds)
true_tokens, true_labels = bert_labels2tokens(dl, [x.bert_labels for x in dl.dataset])
assert pred_tokens == true_tokens
tokens_report = flat_classification_report(true_labels, pred_labels, labels=["I_ORG", "I_PER", "I_LOC"], digits=4)
print(tokens_report)
from modules.analyze_utils.main_metrics import precision_recall_f1
results = precision_recall_f1(true_labels, pred_labels)<jupyter_output>processed 56409 tokens with 7534 phrases; found: 7435 phrases; correct: 6518.

precision:  87.67%; recall:  86.51%; FB1:  87.09

	LOC: precision:  93.42%; recall:  82.02%; F1:  87.35 1367

	ORG: precision:  83.34%; recall:  81.91%; F1:  82.62 3799

	PER: precision:  91.45%; recall:  98.25%; F1:  94.73 2269
{'fraction_non_alphanumeric': 0.10981308411214953, 'fraction_numerical': 0.053738317757009345, 'mean_word_length': 6.646428571428571, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '34136', 'license': 'MIT', 'n_tokens_mistral': 899, 'n_tokens_neox': 821, 'n_words': 136, 'path': 'exps/fre BERTBiLSTMAttnCRF-fit_BERT.ipynb', 'repo_name': 'learnerhouse/ner-bert', 'size': '2140'}