{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# CRF entity recognition evaluation" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from IPython.core.display import Markdown, HTML, display\n", "\n", "import sys\n", "sys.path.insert(0, '..') # noqa\n", "import settings # noqa\n", "\n", "import crf_data_generator as cdg\n", "import pycrfsuite\n", "\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "#data = cdg.ConlluCRFReader(\"../\" + settings.gzipped_conllu_data_root + \"recipes2.conllu.gz\")\n", "data = cdg.ConlluCRFReader(\"filtered_recipes.conllu\")\n", "\n", "data_iterator = iter(data)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "def sentence_as_markdown_table( tokens, labels = None, predictions = None):\n", " n = len(tokens)\n", " s = \"
Sentence: | \\n\"\n", " for t in tokens:\n", " s += f\"{t} | \"\n", " \n", " s += \"
---|---|
labels: | \" + \"\".join([f\"{l} | \" for l in labels])\n", " s += \"Predicitions: | \" + \"\".join([f\"{p} | \" for p in predictions])\n", " \n", " display(HTML(s + \"\\n