{ "cells": [ { "cell_type": "code", "execution_count": 34, "id": "c88056d1-bf3c-477e-9b36-50e7398f9058", "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 35, "id": "186faae4-de4a-4df5-b914-203a4e6296b0", "metadata": {}, "outputs": [], "source": [ "df = pd.read_csv(\"step5.csv\", encoding='utf-8-sig', sep=';')" ] }, { "cell_type": "code", "execution_count": null, "id": "e672cf21-1f91-424c-b944-5d0a12ac69fd", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from sklearn.metrics import classification_report, confusion_matrix\n", "\n", "classification_label_set = {\n", " \"auto\": 0,\n", " \"Business and Industry\": 1,\n", " \"Crime and Justice\": 2,\n", " \"Disaster and Emergency News\": 3,\n", " \"Economics and Finance\": 4,\n", " \"Education\": 5,\n", " \"Entertainment and Culture\": 6,\n", " \"Environment and Climate\": 7,\n", " \"Family and Relationships\": 8,\n", " \"Fashion\": 9,\n", " \"Food and Drink\": 10,\n", " \"Health and Medicine\": 11,\n", " \"Transportation and Infrastructure\": 12,\n", " \"Mental Health and Wellness\": 13,\n", " \"Politics and Government\": 14,\n", " \"Religion\": 15,\n", " \"Sports\": 16,\n", " \"Travel and Leisure\": 17,\n", " \"Technology and Science\": 18\n", "}\n", "\n", "\n", "classification_label_dict = {idx: label for idx, label in enumerate(classification_label_set)}\n", "classification_label_dict_to_index = {v: k for k, v in classification_label_dict.items()}\n", "\n", "\n", "ner_label_set = [\"PAD\",\"O\",\n", " \"B-ORG\", \"I-ORG\", \"B-PERSON\", \"I-PERSON\", \"B-CARDINAL\", \"I-CARDINAL\",\n", " \"B-GPE\", \"I-GPE\", \"B-DATE\", \"I-DATE\", \"B-ORDINAL\", \"I-ORDINAL\",\n", " \"B-PERCENT\", \"I-PERCENT\", \"B-LOC\", \"I-LOC\", \"B-NORP\", \"I-NORP\",\n", " \"B-MONEY\", \"I-MONEY\", \"B-TIME\", \"I-TIME\", \"B-EVENT\", \"I-EVENT\",\n", " \"B-PRODUCT\", \"I-PRODUCT\", \"B-FAC\", \"I-FAC\", \"B-QUANTITY\", \"I-QUANTITY\"\n", "]\n", "\n", "\n", "ner_label_dict = {label: idx for idx, label in enumerate(ner_label_set)}\n", "\n", "ner_label_dict_reverse = {idx: label for label, idx in ner_label_dict.items()}" ] }, { "cell_type": "code", "execution_count": 37, "id": "ced20ed4-b3ca-4401-9221-82bc6e42cfd9", "metadata": {}, "outputs": [], "source": [ "from transformers import AutoTokenizer\n", "model_name = \"nlpaueb/bert-base-greek-uncased-v1\"\n", "tokenizer = AutoTokenizer.from_pretrained(model_name)\n" ] }, { "cell_type": "code", "execution_count": 38, "id": "6360e73b-ddea-4c9b-ac30-366e5f843498", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | url | \n", "title | \n", "text | \n", "label | \n", "clean_text | \n", "ner_results | \n", "ner_sequence | \n", "words | \n", "entities | \n", "entities_parsed | \n", "entities_numbers | \n", "label_numbers | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "https://www.sport-fm.gr/article/o-roueda-sti-S... | \n", "Ο πρώην της Ferrari πήγε στην Sauber | \n", "Τον πρώην επικεφαλής στρατηγικής και αθλητικό ... | \n", "auto | \n", "Ο πρώην της Ferrari πήγε στην Sauber Τον πρώην... | \n", "[{'text': 'ferrari', 'type': 'ORG', 'start_pos... | \n", "[{'word': 'Ο', 'entity': 'O'}, {'word': 'πρώην... | \n", "['Ο', 'πρώην', 'της', 'Ferrari', 'πήγε', 'στην... | \n", "['O', 'O', 'O', 'B-ORG', 'O', 'O', 'B-ORG', 'O... | \n", "['O', 'O', 'O', 'B-ORG', 'O', 'O', 'B-ORG', 'O... | \n", "[1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, ... | \n", "0 | \n", "