diff --git a/langchain-experiments/compare-models.ipynb b/langchain-experiments/compare-models.ipynb index db7567f39ff84d6039331e0303dc57bd9586c6c2..2901942367cbbda9eb06d6124d5a60010bdc6244 100644 --- a/langchain-experiments/compare-models.ipynb +++ b/langchain-experiments/compare-models.ipynb @@ -1,16 +1,25 @@ { "cells": [ { - "cell_type": "code", - "execution_count": 1, - "id": "e46d0648c1c6c96a", + "cell_type": "markdown", + "source": [ + "# Comparing OpenAI and open LLMs\n", + "\n", + "Using the text-only content of the website of the journal AUR - Agrar- und Umweltrecht, we compare the performance of\n", + "GPT-4, GPT-3.5-turbo and Models available on Huggingface.\n", + "\n", + "## Prpeparation\n", + "\n", + "Import dependencies, define shorthand functions, and prepare test data" + ], "metadata": { - "collapsed": true, - "ExecuteTime": { - "end_time": "2024-01-16T18:51:39.319347300Z", - "start_time": "2024-01-16T18:51:32.944085Z" - } + "collapsed": false }, + "id": "396ebd275b60c720" + }, + { + "cell_type": "code", + "execution_count": 1, "outputs": [], "source": [ "import io\n", @@ -38,23 +47,69 @@ " )\n", " return response_to_df(chain.invoke(params))\n", "\n", - "template = \"\"\"\n", - "Finde im folgenden Webseiten-Text die Herausgeber, Redaktion/Schriftleitung und Beirat der Zeitschrift '{journal_name}' und gebe sie im CSV-Format zurück mit den Spalten 'lastname', 'firstname', 'title', 'position', 'affiliation','role'. Die Spalte 'role' enthält entweder 'Herausgeber', 'Redaktion', 'Beirat', 'Schriftleitung' oder ist leer wenn nicht bestimmbar.Wenn die Zeitschrift von einer juristischen Person (Verein, Universität, Institut etc.) herausgegeben wird, gebe den Namen der Institution in der Spalte 'lastname' an. Wenn keine passenden Informationen verfügbar sind, gebe nur den CSV-Header zurück. Setze alle Werte in den CSV-Spalten in Anführungszeichen. Antworte ohne zusätzlichen Kommentar, sondern nur mit den CSV-Daten.\n", - "\n", - "{website_text}\n", - "\"\"\"\n", - "\n", "with open('data/input/journal-website.txt', encoding='utf-8') as f:\n", " website_text = f.read()\n", "journal_name = \"AUR - Agrar- und Umweltrecht\"" - ] + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-01-17T19:43:14.633251500Z", + "start_time": "2024-01-17T19:43:07.158102900Z" + } + }, + "id": "e46d0648c1c6c96a" + }, + { + "cell_type": "markdown", + "source": [ + "## Prompt\n", + "\n", + "OpenAI's GPT-4 works perfectly with a German-language Prompt, and a very minimal prompt returns the data we need. In contrast, the open models performed miserably with that prompt. We therefore use English and provide very detailed instructions. " + ], + "metadata": { + "collapsed": false + }, + "id": "eb805270480fbfb5" + }, + { + "cell_type": "code", + "execution_count": 2, + "outputs": [], + "source": [ + "template = \"\"\"\n", + "In the following German text, which was scraped from a website, find the members of the editorial board or the advisory board of the journal '{journal_name}' as per the following rules:\n", + "- In German, typical labels for these roles are \"Herausgeber\", \"Redaktion/Redakteur/Schriftleitung\" and \"Beirat\". \n", + "- Return the data as comma-separated values, which can be saved to a `.csv` file. Put all values in the CSV rows in quotes. \n", + "- The CSV data must have the columns 'lastname', 'firstname', 'title', 'position', 'affiliation','role'. \n", + "- The column 'role' must contain either 'Herausgeber', 'Redaktion', 'Beirat' or is empty. Leave the column empty if you cannot determine the role. Use 'Redaktion' for the \"Schriftleitung\" role.\n", + "- The column 'title' should contain academic titles such as \"Dr.\" or \"Prof. Dr.\"\n", + "- The column 'position' should contain the job title\n", + "- The column 'affiliation' contains the institution or organization the person belongs to, or the city if one is mentioned\n", + "- If the journal is published (\"herausgeben von\") by an association, institute or other organization, but its name in the column 'lastname'. \n", + "- If you cannot find any information, simply return the CSV header. \n", + "- You must not output any introduction, commentary or explanation such as 'Here is the CSV data for the members of the editorial board or the advisory board of the journal'. Only return the data.\n", + "\n", + "{website_text}\n", + "\"\"\"" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-01-17T19:43:17.827291400Z", + "start_time": "2024-01-17T19:43:17.811637900Z" + } + }, + "id": "23aef80911796078" }, { "cell_type": "markdown", "source": [ "## ChatGPT-4 \n", "\n", - "see [result](data/output/editors-openai-gpt-4.csv)" + "GPT-4 delivers an almost perfect [result](data/output/editors-openai-gpt-4.csv). There are some problems left which could be \n", + "resolved by adding some more instructions to the prompt. \n", + "\n" ], "metadata": { "collapsed": false @@ -63,14 +118,14 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 3, "outputs": [ { "data": { - "text/plain": " lastname firstname title \\\n0 Deutsche Gesellschaft für Agrarrecht NaN NaN \n1 Busse Christian Dr. \n2 Endres Ewald Prof. Dr. \n3 Francois Matthias Dr. \n4 von Garmissen Bernd Dr. \n5 Glas Ingo Dr. \n6 Graß Christiane NaN \n7 Haarstrich Jens NaN \n8 Koch Erich Dr. \n9 Köpl Christian Dr. \n10 Martinez Jose Prof. Dr. \n11 Nies Volkmar NaN \n12 Stephany Ralf NaN \n13 Wedemeyer Harald NaN \n14 Institut für Landwirtschaftsrecht NaN NaN \n15 Martinez José Prof. Dr. \n16 Nies Volkmar LLD \n17 Schell Irina Valeska NaN \n\n position \\\n0 NaN \n1 Regierungsdirektor \n2 NaN \n3 Rechtsanwalt \n4 Rechtsanwalt \n5 Rechtsanwalt \n6 Rechtsanwältin \n7 Rechtsanwalt \n8 Ltd. Verwaltungsdirektor \n9 Ministerialrat \n10 NaN \n11 Ltd. Landwirtschaftsdirektor \n12 Rechtsanwalt/Steuerberater \n13 Rechtsanwalt \n14 NaN \n15 Erster Schriftleiter \n16 Zweiter Schriftleiter \n17 Assistenz der Schriftleitung \n\n affiliation role \n0 NaN Herausgeber \n1 Bundesministerium für Ernährung und Landwirtsc... Redaktion \n2 Hochschule Weihenstephan-Triesdorf, Freising Redaktion \n3 NaN Redaktion \n4 NaN Redaktion \n5 NaN Redaktion \n6 NaN Redaktion \n7 NaN Redaktion \n8 Sozialversicherung für Landwirtschaft, Forsten... Redaktion \n9 Bayerisches Staatsministerium für Ernährung, L... Redaktion \n10 Institut für Landwirtschaftsrecht, Georg-Augus... Redaktion \n11 Landwirtschaftskammer NRW, Bonn Redaktion \n12 NaN Redaktion \n13 Landvolk Niedersachsen, Hannover Redaktion \n14 NaN Schriftleitung \n15 Institut für Landwirtschaftsrecht Schriftleitung \n16 NaN Schriftleitung \n17 NaN Schriftleitung ", - "text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>lastname</th>\n <th>firstname</th>\n <th>title</th>\n <th>position</th>\n <th>affiliation</th>\n <th>role</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>Deutsche Gesellschaft für Agrarrecht</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>Herausgeber</td>\n </tr>\n <tr>\n <th>1</th>\n <td>Busse</td>\n <td>Christian</td>\n <td>Dr.</td>\n <td>Regierungsdirektor</td>\n <td>Bundesministerium für Ernährung und Landwirtsc...</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>2</th>\n <td>Endres</td>\n <td>Ewald</td>\n <td>Prof. Dr.</td>\n <td>NaN</td>\n <td>Hochschule Weihenstephan-Triesdorf, Freising</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>3</th>\n <td>Francois</td>\n <td>Matthias</td>\n <td>Dr.</td>\n <td>Rechtsanwalt</td>\n <td>NaN</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>4</th>\n <td>von Garmissen</td>\n <td>Bernd</td>\n <td>Dr.</td>\n <td>Rechtsanwalt</td>\n <td>NaN</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>5</th>\n <td>Glas</td>\n <td>Ingo</td>\n <td>Dr.</td>\n <td>Rechtsanwalt</td>\n <td>NaN</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>6</th>\n <td>Graß</td>\n <td>Christiane</td>\n <td>NaN</td>\n <td>Rechtsanwältin</td>\n <td>NaN</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>7</th>\n <td>Haarstrich</td>\n <td>Jens</td>\n <td>NaN</td>\n <td>Rechtsanwalt</td>\n <td>NaN</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>8</th>\n <td>Koch</td>\n <td>Erich</td>\n <td>Dr.</td>\n <td>Ltd. Verwaltungsdirektor</td>\n <td>Sozialversicherung für Landwirtschaft, Forsten...</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>9</th>\n <td>Köpl</td>\n <td>Christian</td>\n <td>Dr.</td>\n <td>Ministerialrat</td>\n <td>Bayerisches Staatsministerium für Ernährung, L...</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>10</th>\n <td>Martinez</td>\n <td>Jose</td>\n <td>Prof. Dr.</td>\n <td>NaN</td>\n <td>Institut für Landwirtschaftsrecht, Georg-Augus...</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>11</th>\n <td>Nies</td>\n <td>Volkmar</td>\n <td>NaN</td>\n <td>Ltd. Landwirtschaftsdirektor</td>\n <td>Landwirtschaftskammer NRW, Bonn</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>12</th>\n <td>Stephany</td>\n <td>Ralf</td>\n <td>NaN</td>\n <td>Rechtsanwalt/Steuerberater</td>\n <td>NaN</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>13</th>\n <td>Wedemeyer</td>\n <td>Harald</td>\n <td>NaN</td>\n <td>Rechtsanwalt</td>\n <td>Landvolk Niedersachsen, Hannover</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>14</th>\n <td>Institut für Landwirtschaftsrecht</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>Schriftleitung</td>\n </tr>\n <tr>\n <th>15</th>\n <td>Martinez</td>\n <td>José</td>\n <td>Prof. Dr.</td>\n <td>Erster Schriftleiter</td>\n <td>Institut für Landwirtschaftsrecht</td>\n <td>Schriftleitung</td>\n </tr>\n <tr>\n <th>16</th>\n <td>Nies</td>\n <td>Volkmar</td>\n <td>LLD</td>\n <td>Zweiter Schriftleiter</td>\n <td>NaN</td>\n <td>Schriftleitung</td>\n </tr>\n <tr>\n <th>17</th>\n <td>Schell</td>\n <td>Irina Valeska</td>\n <td>NaN</td>\n <td>Assistenz der Schriftleitung</td>\n <td>NaN</td>\n <td>Schriftleitung</td>\n </tr>\n </tbody>\n</table>\n</div>" + "text/plain": " lastname firstname title \\\n0 DGAR NaN NaN \n1 Busse Christian Dr. \n2 Endres Ewald Prof. Dr. \n3 Francois Matthias Dr. \n4 von Garmissen Bernd Dr. \n5 Glas Ingo NaN \n6 Graß Christiane NaN \n7 Haarstrich Jens NaN \n8 Koch Erich Dr. \n9 Köpl Christian Dr. \n10 Martinez Jose Prof. Dr. \n11 Nies Volkmar NaN \n12 Stephany Ralf NaN \n13 Wedemeyer Harald NaN \n14 Martinez José Prof. Dr. \n15 Nies Volkmar LLD \n\n position \\\n0 Deutsche Gesellschaft für Agrarrecht \n1 Regierungsdirektor \n2 NaN \n3 Rechtsanwalt \n4 Rechtsanwalt \n5 Rechtsanwalt \n6 Rechtsanwältin \n7 Rechtsanwalt \n8 Ltd. Verwaltungsdirektor \n9 Ministerialrat \n10 NaN \n11 Ltd. Landwirtschaftsdirektor \n12 Rechtsanwalt/Steuerberater \n13 Rechtsanwalt \n14 Erster Schriftleiter \n15 Zweiter Schriftleiter \n\n affiliation role \n0 NaN Herausgeber \n1 Bundesministerium für Ernährung und Landwirtsc... Redaktion \n2 Hochschule Weihenstephan-Triesdorf, Freising Redaktion \n3 Bitburg Redaktion \n4 Göttingen Redaktion \n5 Rostock Redaktion \n6 Bonn Redaktion \n7 Peine Redaktion \n8 Sozialversicherung für Landwirtschaft, Forsten... Redaktion \n9 Bayerisches Staatsministerium für Ernährung, L... Redaktion \n10 Institut für Landwirtschaftsrecht, Georg-Augus... Redaktion \n11 Landwirtschaftskammer NRW, Bonn Redaktion \n12 Bonn Redaktion \n13 Landvolk Niedersachsen, Hannover Redaktion \n14 Institut für Landwirtschaftsrecht, Göttingen Redaktion \n15 50170 Kerpen Redaktion ", + "text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>lastname</th>\n <th>firstname</th>\n <th>title</th>\n <th>position</th>\n <th>affiliation</th>\n <th>role</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>DGAR</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>Deutsche Gesellschaft für Agrarrecht</td>\n <td>NaN</td>\n <td>Herausgeber</td>\n </tr>\n <tr>\n <th>1</th>\n <td>Busse</td>\n <td>Christian</td>\n <td>Dr.</td>\n <td>Regierungsdirektor</td>\n <td>Bundesministerium für Ernährung und Landwirtsc...</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>2</th>\n <td>Endres</td>\n <td>Ewald</td>\n <td>Prof. Dr.</td>\n <td>NaN</td>\n <td>Hochschule Weihenstephan-Triesdorf, Freising</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>3</th>\n <td>Francois</td>\n <td>Matthias</td>\n <td>Dr.</td>\n <td>Rechtsanwalt</td>\n <td>Bitburg</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>4</th>\n <td>von Garmissen</td>\n <td>Bernd</td>\n <td>Dr.</td>\n <td>Rechtsanwalt</td>\n <td>Göttingen</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>5</th>\n <td>Glas</td>\n <td>Ingo</td>\n <td>NaN</td>\n <td>Rechtsanwalt</td>\n <td>Rostock</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>6</th>\n <td>Graß</td>\n <td>Christiane</td>\n <td>NaN</td>\n <td>Rechtsanwältin</td>\n <td>Bonn</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>7</th>\n <td>Haarstrich</td>\n <td>Jens</td>\n <td>NaN</td>\n <td>Rechtsanwalt</td>\n <td>Peine</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>8</th>\n <td>Koch</td>\n <td>Erich</td>\n <td>Dr.</td>\n <td>Ltd. Verwaltungsdirektor</td>\n <td>Sozialversicherung für Landwirtschaft, Forsten...</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>9</th>\n <td>Köpl</td>\n <td>Christian</td>\n <td>Dr.</td>\n <td>Ministerialrat</td>\n <td>Bayerisches Staatsministerium für Ernährung, L...</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>10</th>\n <td>Martinez</td>\n <td>Jose</td>\n <td>Prof. Dr.</td>\n <td>NaN</td>\n <td>Institut für Landwirtschaftsrecht, Georg-Augus...</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>11</th>\n <td>Nies</td>\n <td>Volkmar</td>\n <td>NaN</td>\n <td>Ltd. Landwirtschaftsdirektor</td>\n <td>Landwirtschaftskammer NRW, Bonn</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>12</th>\n <td>Stephany</td>\n <td>Ralf</td>\n <td>NaN</td>\n <td>Rechtsanwalt/Steuerberater</td>\n <td>Bonn</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>13</th>\n <td>Wedemeyer</td>\n <td>Harald</td>\n <td>NaN</td>\n <td>Rechtsanwalt</td>\n <td>Landvolk Niedersachsen, Hannover</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>14</th>\n <td>Martinez</td>\n <td>José</td>\n <td>Prof. Dr.</td>\n <td>Erster Schriftleiter</td>\n <td>Institut für Landwirtschaftsrecht, Göttingen</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>15</th>\n <td>Nies</td>\n <td>Volkmar</td>\n <td>LLD</td>\n <td>Zweiter Schriftleiter</td>\n <td>50170 Kerpen</td>\n <td>Redaktion</td>\n </tr>\n </tbody>\n</table>\n</div>" }, - "execution_count": 14, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -84,7 +139,8 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "start_time": "2024-01-16T17:24:51.851287400Z" + "end_time": "2024-01-17T19:43:51.821749100Z", + "start_time": "2024-01-17T19:43:22.643583400Z" } }, "id": "initial_id" @@ -94,7 +150,8 @@ "source": [ "## ChatGPT 3.5-turbo\n", "\n", - "see [result](data/output/editors-openai-gpt-3.5-turbo.csv)\n" + "GPT-3.5 [performs less well](data/output/editors-openai-gpt-3.5-turbo.csv), but still ok. It gets some of the 'title' amd 'position' \n", + "column data confused, and does not recognize the institutional publisher (Herausgeber) of the journal. \n" ], "metadata": { "collapsed": false @@ -103,14 +160,14 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 4, "outputs": [ { "data": { - "text/plain": " lastname firstname title \\\n0 Deutsche Gesellschaft für Agrarrecht \n1 Regierungsdirektor Dr. Christian \n2 Prof. Dr. Ewald \n3 Rechtsanwalt Dr. Matthias \n4 Rechtsanwalt Dr. Bernd von Garmissen \n5 Rechtsanwalt Ingo \n6 Rechtsanwältin Christiane \n7 Rechtsanwalt Jens \n8 Ltd. Verwaltungsdirektor Dr. Erich \n9 Ministerialrat Dr. Christian \n10 Prof. Dr. Jose \n11 Ltd. Landwirtschaftsdirektor Volkmar \n12 Rechtsanwalt/Steuerberater Ralf \n13 Rechtsanwalt Harald \n14 Prof. Dr. José \n15 LLD Volkmar \n16 Irina Valeska Schell \n\n position \\\n0 Herausgeber \n1 Redaktion \n2 Redaktion \n3 Redaktion \n4 Redaktion \n5 Redaktion \n6 Redaktion \n7 Redaktion \n8 Redaktion \n9 Redaktion \n10 Redaktion \n11 Redaktion \n12 Redaktion \n13 Redaktion \n14 Schriftleitung \n15 Schriftleitung \n16 Assistenz der Schriftleitung \n\n affiliation role \n0 \n1 Bundesministerium für Ernährung und Landwirtsc... \n2 Hochschule Weihenstephan-Triesdorf, Freising \n3 Bitburg \n4 Göttingen \n5 Rostock \n6 Bonn \n7 Peine \n8 Sozialversicherung für Landwirtschaft, Forsten... \n9 Bayerisches Staatsministerium für Ernährung, L... \n10 Institut für Landwirtschaftsrecht, Georg-Augus... \n11 Landwirtschaftskammer NRW, Bonn \n12 Bonn \n13 Landvolk Niedersachsen, Hannover \n14 Institut für Landwirtschaftsrecht \n15 \n16 ", - "text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>lastname</th>\n <th>firstname</th>\n <th>title</th>\n <th>position</th>\n <th>affiliation</th>\n <th>role</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>Deutsche Gesellschaft für Agrarrecht</td>\n <td></td>\n <td></td>\n <td>Herausgeber</td>\n <td></td>\n <td></td>\n </tr>\n <tr>\n <th>1</th>\n <td>Regierungsdirektor</td>\n <td>Dr. Christian</td>\n <td></td>\n <td>Redaktion</td>\n <td>Bundesministerium für Ernährung und Landwirtsc...</td>\n <td></td>\n </tr>\n <tr>\n <th>2</th>\n <td>Prof. Dr.</td>\n <td>Ewald</td>\n <td></td>\n <td>Redaktion</td>\n <td>Hochschule Weihenstephan-Triesdorf, Freising</td>\n <td></td>\n </tr>\n <tr>\n <th>3</th>\n <td>Rechtsanwalt</td>\n <td>Dr. Matthias</td>\n <td></td>\n <td>Redaktion</td>\n <td>Bitburg</td>\n <td></td>\n </tr>\n <tr>\n <th>4</th>\n <td>Rechtsanwalt</td>\n <td>Dr. Bernd</td>\n <td>von Garmissen</td>\n <td>Redaktion</td>\n <td>Göttingen</td>\n <td></td>\n </tr>\n <tr>\n <th>5</th>\n <td>Rechtsanwalt</td>\n <td>Ingo</td>\n <td></td>\n <td>Redaktion</td>\n <td>Rostock</td>\n <td></td>\n </tr>\n <tr>\n <th>6</th>\n <td>Rechtsanwältin</td>\n <td>Christiane</td>\n <td></td>\n <td>Redaktion</td>\n <td>Bonn</td>\n <td></td>\n </tr>\n <tr>\n <th>7</th>\n <td>Rechtsanwalt</td>\n <td>Jens</td>\n <td></td>\n <td>Redaktion</td>\n <td>Peine</td>\n <td></td>\n </tr>\n <tr>\n <th>8</th>\n <td>Ltd. Verwaltungsdirektor</td>\n <td>Dr. Erich</td>\n <td></td>\n <td>Redaktion</td>\n <td>Sozialversicherung für Landwirtschaft, Forsten...</td>\n <td></td>\n </tr>\n <tr>\n <th>9</th>\n <td>Ministerialrat</td>\n <td>Dr. Christian</td>\n <td></td>\n <td>Redaktion</td>\n <td>Bayerisches Staatsministerium für Ernährung, L...</td>\n <td></td>\n </tr>\n <tr>\n <th>10</th>\n <td>Prof. Dr.</td>\n <td>Jose</td>\n <td></td>\n <td>Redaktion</td>\n <td>Institut für Landwirtschaftsrecht, Georg-Augus...</td>\n <td></td>\n </tr>\n <tr>\n <th>11</th>\n <td>Ltd. Landwirtschaftsdirektor</td>\n <td>Volkmar</td>\n <td></td>\n <td>Redaktion</td>\n <td>Landwirtschaftskammer NRW, Bonn</td>\n <td></td>\n </tr>\n <tr>\n <th>12</th>\n <td>Rechtsanwalt/Steuerberater</td>\n <td>Ralf</td>\n <td></td>\n <td>Redaktion</td>\n <td>Bonn</td>\n <td></td>\n </tr>\n <tr>\n <th>13</th>\n <td>Rechtsanwalt</td>\n <td>Harald</td>\n <td></td>\n <td>Redaktion</td>\n <td>Landvolk Niedersachsen, Hannover</td>\n <td></td>\n </tr>\n <tr>\n <th>14</th>\n <td>Prof. Dr.</td>\n <td>José</td>\n <td></td>\n <td>Schriftleitung</td>\n <td>Institut für Landwirtschaftsrecht</td>\n <td></td>\n </tr>\n <tr>\n <th>15</th>\n <td>LLD</td>\n <td>Volkmar</td>\n <td></td>\n <td>Schriftleitung</td>\n <td></td>\n <td></td>\n </tr>\n <tr>\n <th>16</th>\n <td>Irina Valeska</td>\n <td>Schell</td>\n <td></td>\n <td>Assistenz der Schriftleitung</td>\n <td></td>\n <td></td>\n </tr>\n </tbody>\n</table>\n</div>" + "text/plain": " lastname firstname title \\\n0 Busse Christian Dr. \n1 Endres Ewald Prof. Dr. \n2 Francois Matthias Dr. \n3 von Garmissen Bernd Dr. \n4 Glas Ingo NaN \n5 Graß Christiane Rechtsanwältin \n6 Haarstrich Jens Rechtsanwalt \n7 Koch Erich Dr. \n8 Köpl Christian Dr. \n9 Martinez Jose Prof. Dr. \n10 Nies Volkmar Ltd. Landwirtschaftsdirektor \n11 Stephany Ralf Rechtsanwalt/Steuerberater \n12 Wedemeyer Harald Rechtsanwalt \n\n position \\\n0 Regierungsdirektor \n1 NaN \n2 Rechtsanwalt \n3 Rechtsanwalt \n4 Rechtsanwalt \n5 NaN \n6 NaN \n7 Ltd. Verwaltungsdirektor \n8 Ministerialrat \n9 NaN \n10 NaN \n11 NaN \n12 NaN \n\n affiliation role \n0 Bundesministerium für Ernährung und Landwirtsc... Redaktion \n1 Hochschule Weihenstephan-Triesdorf, Freising Redaktion \n2 Bitburg Redaktion \n3 Göttingen Redaktion \n4 Rostock Redaktion \n5 Bonn Redaktion \n6 Peine Redaktion \n7 Sozialversicherung für Landwirtschaft, Forsten... Redaktion \n8 Bayerisches Staatsministerium für Ernährung, L... Redaktion \n9 Institut für Landwirtschaftsrecht, Georg-Augus... Redaktion \n10 Landwirtschaftskammer NRW, Bonn Redaktion \n11 Bonn Redaktion \n12 Landvolk Niedersachsen, Hannover Redaktion ", + "text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>lastname</th>\n <th>firstname</th>\n <th>title</th>\n <th>position</th>\n <th>affiliation</th>\n <th>role</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>Busse</td>\n <td>Christian</td>\n <td>Dr.</td>\n <td>Regierungsdirektor</td>\n <td>Bundesministerium für Ernährung und Landwirtsc...</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>1</th>\n <td>Endres</td>\n <td>Ewald</td>\n <td>Prof. Dr.</td>\n <td>NaN</td>\n <td>Hochschule Weihenstephan-Triesdorf, Freising</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>2</th>\n <td>Francois</td>\n <td>Matthias</td>\n <td>Dr.</td>\n <td>Rechtsanwalt</td>\n <td>Bitburg</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>3</th>\n <td>von Garmissen</td>\n <td>Bernd</td>\n <td>Dr.</td>\n <td>Rechtsanwalt</td>\n <td>Göttingen</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>4</th>\n <td>Glas</td>\n <td>Ingo</td>\n <td>NaN</td>\n <td>Rechtsanwalt</td>\n <td>Rostock</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>5</th>\n <td>Graß</td>\n <td>Christiane</td>\n <td>Rechtsanwältin</td>\n <td>NaN</td>\n <td>Bonn</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>6</th>\n <td>Haarstrich</td>\n <td>Jens</td>\n <td>Rechtsanwalt</td>\n <td>NaN</td>\n <td>Peine</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>7</th>\n <td>Koch</td>\n <td>Erich</td>\n <td>Dr.</td>\n <td>Ltd. Verwaltungsdirektor</td>\n <td>Sozialversicherung für Landwirtschaft, Forsten...</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>8</th>\n <td>Köpl</td>\n <td>Christian</td>\n <td>Dr.</td>\n <td>Ministerialrat</td>\n <td>Bayerisches Staatsministerium für Ernährung, L...</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>9</th>\n <td>Martinez</td>\n <td>Jose</td>\n <td>Prof. Dr.</td>\n <td>NaN</td>\n <td>Institut für Landwirtschaftsrecht, Georg-Augus...</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>10</th>\n <td>Nies</td>\n <td>Volkmar</td>\n <td>Ltd. Landwirtschaftsdirektor</td>\n <td>NaN</td>\n <td>Landwirtschaftskammer NRW, Bonn</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>11</th>\n <td>Stephany</td>\n <td>Ralf</td>\n <td>Rechtsanwalt/Steuerberater</td>\n <td>NaN</td>\n <td>Bonn</td>\n <td>Redaktion</td>\n </tr>\n <tr>\n <th>12</th>\n <td>Wedemeyer</td>\n <td>Harald</td>\n <td>Rechtsanwalt</td>\n <td>NaN</td>\n <td>Landvolk Niedersachsen, Hannover</td>\n <td>Redaktion</td>\n </tr>\n </tbody>\n</table>\n</div>" }, - "execution_count": 15, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -124,8 +181,8 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-01-16T17:26:16.567722400Z", - "start_time": "2024-01-16T17:25:56.403589200Z" + "end_time": "2024-01-17T19:46:04.139744300Z", + "start_time": "2024-01-17T19:45:46.825487Z" } }, "id": "e1aedc5ef3cab564" @@ -133,9 +190,19 @@ { "cell_type": "markdown", "source": [ - "## TheBloke/Llama-2-13B-chat-GPTQ via Huggingface Inference Endpoint\n", + "Now, let's try the open models via the Huggingface Inference Endpoint" + ], + "metadata": { + "collapsed": false + }, + "id": "31084716e138fe06" + }, + { + "cell_type": "markdown", + "source": [ + "## TheBloke/Llama-2-13B-chat-GPTQ \n", "\n", - "https://huggingface.co/TheBloke/Llama-2-13B-chat-GPTQ" + "The [LLama2 13 billion parameter model](https://huggingface.co/TheBloke/Llama-2-13B-chat-GPTQ) produces [unusuable output](data/output/editors-llama-2-13b-chat-gptq.txt)." ], "metadata": { "collapsed": false @@ -144,19 +211,19 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 4, "outputs": [ { "data": { - "text/plain": "['',\n 'Martinez,José,Professor',\n 'Busse,Regierungsdirektor',\n 'Ewald,Endres,Forst,Jurist',\n 'Glas,VolkmarNies,Koch',\n '',\n '',\n 'Note: Some positions have been omitted as they are not explicitly mentioned in the text.']" + "text/plain": "['Martinez, Dr. Christian Busse, Bundesministerium für Ernährung und Landwirtschaft, Bonn Agrarprodukt Recht',\n 'Prof. Dr. Ewald Endres, Hochschule Weihenstephan-Triesdorf Freising Forsting Forsting, Jagd, Fischerei, Fischerei',\n 'Lawyeranwalt Ingo Glas, Bitburg Boden Recht',\n 'Christiane Grass, Bonn Agrarzivil Recht',\n 'Jens Haarstrich, Peine Redaktionär, Rostock',\n 'Prof. Dr. Bernd von Garmissen, Göttingen Erb, Redaktion, Umwelt',\n 'Ltdr. Jose Martinez, Georg-August-Universität Göttingen, Göttingen',\n '',\n '',\n \"Note: The column 'Role' contains the following values: 'Herausgeber', 'Redaktion', 'Beirat'\"]" }, - "execution_count": 2, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "from lib.hf_llama2_13b_chat import query\n", + "from lib.hf_llama2_13b_chat_gptq import query\n", "\n", "lines = query(template, journal_name=journal_name, website_text=website_text).split(\"\\n\")[4:]\n", "lines" @@ -164,20 +231,48 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-01-16T18:51:42.730907700Z", - "start_time": "2024-01-16T18:51:39.319347300Z" + "end_time": "2024-01-17T19:31:23.221568600Z", + "start_time": "2024-01-17T19:31:16.694648400Z" } }, "id": "f05098a4cf2aa3dc" }, { - "cell_type": "code", - "execution_count": null, - "outputs": [], - "source": [], + "cell_type": "markdown", + "source": [ + "## TheBloke/Llama-2-70B-chat-GPTQ via Huggingface Inference Endpoint\n", + "\n", + "The 70 billion parameter variant [does a bit better](data/output/editors-llama-2-70b-chat-gptq.csv) but, among other things, doesn't the academic titles right. It also cannot be persuaded to [not comment on the CSV output].(data/output/editors-llama-2-70b-chat-gptq.txt)" + ], "metadata": { "collapsed": false }, + "id": "ca33fb28f6772cbc" + }, + { + "cell_type": "code", + "execution_count": 3, + "outputs": [ + { + "data": { + "text/plain": "' Here is the CSV data for the members of the editorial board or the advisory board of the journal \\'AUR - Agrar- und Umweltrecht\\':\\n\\n\"lastname\",\"firstname\",\"title\",\"affiliation\",\"role\"\\n\"Busse\",\"Christian\", \"Regierungsdirektor\", \"Bundesministerium für Ernährung und Landwirtschaft, Bonn\", \"Herausgeber\"\\n\"Endres\",\"Ewald\", \"Prof. Dr.\", \"Hochschule Weihenstephan-Triesdorf, Freising\", \"Redaktion\"\\n\"Francois\",\"Matthias\", \"Rechtsanwalt\", \"Bitburg\", \"Redaktion\"\\n\"Garmissen\",\"Bernd\", \"Rechtsanwalt\", \"Göttingen\", \"Redaktion\"\\n\"Graß\",\"Christiane\", \"Rechtsanwältin\", \"Bonn\", \"Redaktion\"\\n\"Haarstrich\",\"Jens\", \"Rechtsanwalt\", \"Peine\", \"Redaktion\"\\n\"Köpl\",\"Christian\", \"Ministerialrat\", \"Bayerisches Staatsministerium für Ernährung, Landwirtschaft und Forsten, München\", \"\"\\n\"Martinez\",\"Jose\", \"Prof. Dr.\", \"Institut für Landwirtschaftsrecht, Georg-August-Universität Göttingen, Göttingen\", \"Herausgeber\"\\n\"Nies\",\"Volkmar\", \"Ltd. Landwirtschaftsdirektor\", \"Landwirtschaftskammer NRW, Bonn\", \"Redaktion\"\\n\"Stephany\",\"Ralf\", \"Rechtsanwalt/Steuerberater\", \"Bonn\", \"Redaktion\"\\n\"Wedemeyer\",\"Harald\", \"Rechtsanwalt\", \"Landvolk Niedersachsen, Hannover\", \"Redaktion\"\\n\"Schell\",\"Irina Valeska\", \"\", \"Georg-August-Universität Göttingen, Göttingen\", \"\"\\n\\nNote: The column \\'role\\' is empty for some members, as their role could not be determined.'" + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from lib.hf_llama2_70b_chat_gptq import query\n", + "query(template, journal_name=journal_name, website_text=website_text)" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-01-17T19:14:56.752808800Z", + "start_time": "2024-01-17T19:13:45.800635700Z" + } + }, "id": "b94cf62b996bf3a2" } ], diff --git a/langchain-experiments/data/output/editors-llama-2-13b-chat-gptq.txt b/langchain-experiments/data/output/editors-llama-2-13b-chat-gptq.txt new file mode 100644 index 0000000000000000000000000000000000000000..2b55c30eb4b46bdf3982afd1dc71ff0123029a57 --- /dev/null +++ b/langchain-experiments/data/output/editors-llama-2-13b-chat-gptq.txt @@ -0,0 +1,10 @@ +['Martinez, Dr. Christian Busse, Bundesministerium für Ernährung und Landwirtschaft, Bonn Agrarprodukt Recht', + 'Prof. Dr. Ewald Endres, Hochschule Weihenstephan-Triesdorf Freising Forsting Forsting, Jagd, Fischerei, Fischerei', + 'Lawyeranwalt Ingo Glas, Bitburg Boden Recht', + 'Christiane Grass, Bonn Agrarzivil Recht', + 'Jens Haarstrich, Peine Redaktionär, Rostock', + 'Prof. Dr. Bernd von Garmissen, Göttingen Erb, Redaktion, Umwelt', + 'Ltdr. Jose Martinez, Georg-August-Universität Göttingen, Göttingen', + '', + '', + "Note: The column 'Role' contains the following values: 'Herausgeber', 'Redaktion', 'Beirat'"] \ No newline at end of file diff --git a/langchain-experiments/data/output/editors-llama-2-70b-chat-gptq.csv b/langchain-experiments/data/output/editors-llama-2-70b-chat-gptq.csv new file mode 100644 index 0000000000000000000000000000000000000000..16eb4a14ff0e53f607f68380ede7384f24102b8c --- /dev/null +++ b/langchain-experiments/data/output/editors-llama-2-70b-chat-gptq.csv @@ -0,0 +1,13 @@ +"lastname","firstname","title","affiliation","role" +"Busse","Christian", "Regierungsdirektor", "Bundesministerium für Ernährung und Landwirtschaft, Bonn", "Herausgeber" +"Endres","Ewald", "Prof. Dr.", "Hochschule Weihenstephan-Triesdorf, Freising", "Redaktion" +"Francois","Matthias", "Rechtsanwalt", "Bitburg", "Redaktion" +"Garmissen","Bernd", "Rechtsanwalt", "Göttingen", "Redaktion" +"Graß","Christiane", "Rechtsanwältin", "Bonn", "Redaktion" +"Haarstrich","Jens", "Rechtsanwalt", "Peine", "Redaktion" +"Köpl","Christian", "Ministerialrat", "Bayerisches Staatsministerium für Ernährung, Landwirtschaft und Forsten, München", "" +"Martinez","Jose", "Prof. Dr.", "Institut für Landwirtschaftsrecht, Georg-August-Universität Göttingen, Göttingen", "Herausgeber" +"Nies","Volkmar", "Ltd. Landwirtschaftsdirektor", "Landwirtschaftskammer NRW, Bonn", "Redaktion" +"Stephany","Ralf", "Rechtsanwalt/Steuerberater", "Bonn", "Redaktion" +"Wedemeyer","Harald", "Rechtsanwalt", "Landvolk Niedersachsen, Hannover", "Redaktion" +"Schell","Irina Valeska", "", "Georg-August-Universität Göttingen, Göttingen", "" \ No newline at end of file diff --git a/langchain-experiments/data/output/editors-llama-2-70b-chat-gptq.txt b/langchain-experiments/data/output/editors-llama-2-70b-chat-gptq.txt new file mode 100644 index 0000000000000000000000000000000000000000..d97515c59f6acf567beb0893b8519d48d30ea899 --- /dev/null +++ b/langchain-experiments/data/output/editors-llama-2-70b-chat-gptq.txt @@ -0,0 +1 @@ +' Here is the CSV data for the members of the editorial board or the advisory board of the journal \'AUR - Agrar- und Umweltrecht\':\n\n"lastname","firstname","title","affiliation","role"\n"Busse","Christian", "Regierungsdirektor", "Bundesministerium für Ernährung und Landwirtschaft, Bonn", "Herausgeber"\n"Endres","Ewald", "Prof. Dr.", "Hochschule Weihenstephan-Triesdorf, Freising", "Redaktion"\n"Francois","Matthias", "Rechtsanwalt", "Bitburg", "Redaktion"\n"Garmissen","Bernd", "Rechtsanwalt", "Göttingen", "Redaktion"\n"Graß","Christiane", "Rechtsanwältin", "Bonn", "Redaktion"\n"Haarstrich","Jens", "Rechtsanwalt", "Peine", "Redaktion"\n"Köpl","Christian", "Ministerialrat", "Bayerisches Staatsministerium für Ernährung, Landwirtschaft und Forsten, München", ""\n"Martinez","Jose", "Prof. Dr.", "Institut für Landwirtschaftsrecht, Georg-August-Universität Göttingen, Göttingen", "Herausgeber"\n"Nies","Volkmar", "Ltd. Landwirtschaftsdirektor", "Landwirtschaftskammer NRW, Bonn", "Redaktion"\n"Stephany","Ralf", "Rechtsanwalt/Steuerberater", "Bonn", "Redaktion"\n"Wedemeyer","Harald", "Rechtsanwalt", "Landvolk Niedersachsen, Hannover", "Redaktion"\n"Schell","Irina Valeska", "", "Georg-August-Universität Göttingen, Göttingen", ""\n\nNote: The column \'role\' is empty for some members, as their role could not be determined.' \ No newline at end of file diff --git a/langchain-experiments/data/output/editors-openai-gpt-3.5-turbo.csv b/langchain-experiments/data/output/editors-openai-gpt-3.5-turbo.csv index b96f5a4a3ef5d195f731ea77b08199f20475aaca..f258ec37573e1fc639df8f63870e85da848f0dae 100644 --- a/langchain-experiments/data/output/editors-openai-gpt-3.5-turbo.csv +++ b/langchain-experiments/data/output/editors-openai-gpt-3.5-turbo.csv @@ -1,18 +1,14 @@ ,lastname,firstname,title,position,affiliation,role -0,Deutsche Gesellschaft für Agrarrecht, , ,Herausgeber, , -1,Regierungsdirektor,Dr. Christian, ,Redaktion,"Bundesministerium für Ernährung und Landwirtschaft, Bonn", -2,Prof. Dr.,Ewald, ,Redaktion,"Hochschule Weihenstephan-Triesdorf, Freising", -3,Rechtsanwalt,Dr. Matthias, ,Redaktion,Bitburg, -4,Rechtsanwalt,Dr. Bernd,von Garmissen,Redaktion,Göttingen, -5,Rechtsanwalt,Ingo, ,Redaktion,Rostock, -6,Rechtsanwältin,Christiane, ,Redaktion,Bonn, -7,Rechtsanwalt,Jens, ,Redaktion,Peine, -8,Ltd. Verwaltungsdirektor,Dr. Erich, ,Redaktion,"Sozialversicherung für Landwirtschaft, Forsten und Gartenbau, Kassel", -9,Ministerialrat,Dr. Christian, ,Redaktion,"Bayerisches Staatsministerium für Ernährung, Landwirtschaft und Forsten, München", -10,Prof. Dr.,Jose, ,Redaktion,"Institut für Landwirtschaftsrecht, Georg-August-Universitat Göttingen, Göttingen", -11,Ltd. Landwirtschaftsdirektor,Volkmar, ,Redaktion,"Landwirtschaftskammer NRW, Bonn", -12,Rechtsanwalt/Steuerberater,Ralf, ,Redaktion,Bonn, -13,Rechtsanwalt,Harald, ,Redaktion,"Landvolk Niedersachsen, Hannover", -14,Prof. Dr.,José, ,Schriftleitung,Institut für Landwirtschaftsrecht, -15,LLD,Volkmar, ,Schriftleitung, , -16,Irina Valeska,Schell, ,Assistenz der Schriftleitung, , +0,Busse,Christian,Dr.,Regierungsdirektor,"Bundesministerium für Ernährung und Landwirtschaft, Bonn",Redaktion +1,Endres,Ewald,Prof. Dr.,,"Hochschule Weihenstephan-Triesdorf, Freising",Redaktion +2,Francois,Matthias,Dr.,Rechtsanwalt,Bitburg,Redaktion +3,von Garmissen,Bernd,Dr.,Rechtsanwalt,Göttingen,Redaktion +4,Glas,Ingo,,Rechtsanwalt,Rostock,Redaktion +5,Graß,Christiane,Rechtsanwältin,,Bonn,Redaktion +6,Haarstrich,Jens,Rechtsanwalt,,Peine,Redaktion +7,Koch,Erich,Dr.,Ltd. Verwaltungsdirektor,"Sozialversicherung für Landwirtschaft, Forsten und Gartenbau, Kassel",Redaktion +8,Köpl,Christian,Dr.,Ministerialrat,"Bayerisches Staatsministerium für Ernährung, Landwirtschaft und Forsten, München",Redaktion +9,Martinez,Jose,Prof. Dr.,,"Institut für Landwirtschaftsrecht, Georg-August-Universitat Göttingen, Göttingen",Redaktion +10,Nies,Volkmar,Ltd. Landwirtschaftsdirektor,,"Landwirtschaftskammer NRW, Bonn",Redaktion +11,Stephany,Ralf,Rechtsanwalt/Steuerberater,,Bonn,Redaktion +12,Wedemeyer,Harald,Rechtsanwalt,,"Landvolk Niedersachsen, Hannover",Redaktion diff --git a/langchain-experiments/data/output/editors-openai-gpt-4.csv b/langchain-experiments/data/output/editors-openai-gpt-4.csv index 649cf34e14f879db97f06d3e5de24376b337850c..e90973cd79f05e376335c40952c4e55996463823 100644 --- a/langchain-experiments/data/output/editors-openai-gpt-4.csv +++ b/langchain-experiments/data/output/editors-openai-gpt-4.csv @@ -1,19 +1,17 @@ ,lastname,firstname,title,position,affiliation,role -0,Deutsche Gesellschaft für Agrarrecht,,,,,Herausgeber +0,DGAR,,,Deutsche Gesellschaft für Agrarrecht,,Herausgeber 1,Busse,Christian,Dr.,Regierungsdirektor,"Bundesministerium für Ernährung und Landwirtschaft, Bonn",Redaktion 2,Endres,Ewald,Prof. Dr.,,"Hochschule Weihenstephan-Triesdorf, Freising",Redaktion -3,Francois,Matthias,Dr.,Rechtsanwalt,,Redaktion -4,von Garmissen,Bernd,Dr.,Rechtsanwalt,,Redaktion -5,Glas,Ingo,Dr.,Rechtsanwalt,,Redaktion -6,Graß,Christiane,,Rechtsanwältin,,Redaktion -7,Haarstrich,Jens,,Rechtsanwalt,,Redaktion +3,Francois,Matthias,Dr.,Rechtsanwalt,Bitburg,Redaktion +4,von Garmissen,Bernd,Dr.,Rechtsanwalt,Göttingen,Redaktion +5,Glas,Ingo,,Rechtsanwalt,Rostock,Redaktion +6,Graß,Christiane,,Rechtsanwältin,Bonn,Redaktion +7,Haarstrich,Jens,,Rechtsanwalt,Peine,Redaktion 8,Koch,Erich,Dr.,Ltd. Verwaltungsdirektor,"Sozialversicherung für Landwirtschaft, Forsten und Gartenbau, Kassel",Redaktion 9,Köpl,Christian,Dr.,Ministerialrat,"Bayerisches Staatsministerium für Ernährung, Landwirtschaft und Forsten, München",Redaktion 10,Martinez,Jose,Prof. Dr.,,"Institut für Landwirtschaftsrecht, Georg-August-Universitat Göttingen, Göttingen",Redaktion 11,Nies,Volkmar,,Ltd. Landwirtschaftsdirektor,"Landwirtschaftskammer NRW, Bonn",Redaktion -12,Stephany,Ralf,,Rechtsanwalt/Steuerberater,,Redaktion +12,Stephany,Ralf,,Rechtsanwalt/Steuerberater,Bonn,Redaktion 13,Wedemeyer,Harald,,Rechtsanwalt,"Landvolk Niedersachsen, Hannover",Redaktion -14,Institut für Landwirtschaftsrecht,,,,,Schriftleitung -15,Martinez,José,Prof. Dr.,Erster Schriftleiter,Institut für Landwirtschaftsrecht,Schriftleitung -16,Nies,Volkmar,LLD,Zweiter Schriftleiter,,Schriftleitung -17,Schell,Irina Valeska,,Assistenz der Schriftleitung,,Schriftleitung +14,Martinez,José,Prof. Dr.,Erster Schriftleiter,"Institut für Landwirtschaftsrecht, Göttingen",Redaktion +15,Nies,Volkmar,LLD,Zweiter Schriftleiter,50170 Kerpen,Redaktion diff --git a/langchain-experiments/lib/hf_llama2_13b_chat.py b/langchain-experiments/lib/hf_llama2_13b_chat_gptq.py similarity index 84% rename from langchain-experiments/lib/hf_llama2_13b_chat.py rename to langchain-experiments/lib/hf_llama2_13b_chat_gptq.py index a2418cb699efe8e52bbc8aaa5bc71330e8fca238..dfc43114c3724b8a7d27a5239b76ce19fcab688b 100644 --- a/langchain-experiments/lib/hf_llama2_13b_chat.py +++ b/langchain-experiments/lib/hf_llama2_13b_chat_gptq.py @@ -17,11 +17,12 @@ headers = { def query(template, model_params = None, **params): if model_params is None: model_params = { - "temperature": 0.1 + "temperature": 0.1, + "max_new_tokens": 2000 } prompt = template.format_map(params) payload = { - "inputs": f"<s>[INST] <<SYS>>You are a helpful assistant. You keep your answers short. When asked to provide data such as CSV data or JSON as response, do not return additional comments or notes.<</SYS>>{prompt}[/INST]", + "inputs": f"<s>[INST] <<SYS>>You are a helpful assistant. No comments or explanation, just answer the question.<</SYS>>{prompt}[/INST]", "parameters": model_params } response = requests.post(API_URL, headers=headers, json=payload) diff --git a/langchain-experiments/lib/hf_llama2_70b_chat_gptq.py b/langchain-experiments/lib/hf_llama2_70b_chat_gptq.py new file mode 100644 index 0000000000000000000000000000000000000000..33b3bddbbe2efad92c5f53ead102a7dbe8aa886d --- /dev/null +++ b/langchain-experiments/lib/hf_llama2_70b_chat_gptq.py @@ -0,0 +1,35 @@ +import requests +import os +from dotenv import load_dotenv +from json import JSONDecodeError +import os + +load_dotenv() + +API_KEY = os.getenv("HUGGINGFACEHUB_API_TOKEN") +API_URL = "https://gp8iviqlqee101a0.us-east-1.aws.endpoints.huggingface.cloud" +headers = { + "Accept" : "application/json", + "Authorization": f"Bearer {API_KEY}", + "Content-Type": "application/json" +} + +def query(template, model_params = None, **params): + if model_params is None: + model_params = { + "temperature": 0.1, + "max_new_tokens": 1000 + } + prompt = template.format_map(params) + payload = { + "inputs": f"<s>[INST] <<SYS>>You are a helpful assistant. No comments or explanation, just answer the question.<</SYS>>{prompt}[/INST]", + "parameters": model_params + } + response = requests.post(API_URL, headers=headers, json=payload) + response.raise_for_status() + try: + return response.json()[0].get("generated_text") + except JSONDecodeError: + with open('tmp/response.txt', "w", encoding='utf-8') as f: + f.write(response.text) + raise RuntimeError(f'Cannot parse response from {response.url}. See tmp/response.txt') diff --git a/langchain-experiments/readme.md b/langchain-experiments/readme.md index 724824887dd4c838248a7d09f8b217f82ff5fc6e..e7d1436d6064a91657d6a8ce1d6910b01bfab67c 100644 --- a/langchain-experiments/readme.md +++ b/langchain-experiments/readme.md @@ -1,3 +1,12 @@ # Experiments with https://python.langchain.com -`pip install langchain langchain-cli openai huggingface_hub langchain_openai` \ No newline at end of file +Create a python 3.11 environment and install the following dependencies (somewhat convoluted because of dependency +problems): + +`pip install typing-inspect==0.8.0 typing_extensions==4.5.0` +`pip install pydantic -U` +`pip install pydantic==1.10.11` +`pip install python-dotenv langchain langchain-cli openai huggingface_hub langchain_openai` + +You need to copy `.env.dist` to `.env` and add values for the `OPENAI_API_KEY` and `HUGGINGFACEHUB_API_TOKEN` +emvironment variables. \ No newline at end of file