Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QA with private data - demo notebook #21

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"cells": [
{
"cell_type": "raw",
"metadata": {},
"source": [
"---\n",
"sidebar_position: 2\n",
"title: Multi-language anonymization\n",
"---"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -248,15 +258,15 @@
"import langdetect\n",
"from langchain.schema import runnable\n",
"\n",
"\n",
"def detect_language(text: str) -> dict:\n",
" language = langdetect.detect(text)\n",
" print(language)\n",
" return {\"text\": text, \"language\": language}\n",
"\n",
"\n",
"chain = (\n",
" runnable.RunnableLambda(detect_language)\n",
" | (lambda x: anonymizer.anonymize(x[\"text\"], language=x[\"language\"]))\n",
"chain = runnable.RunnableLambda(detect_language) | (\n",
" lambda x: anonymizer.anonymize(x[\"text\"], language=x[\"language\"])\n",
")"
]
},
Expand Down Expand Up @@ -345,15 +355,17 @@
"import fasttext\n",
"\n",
"model = fasttext.load_model(\"lid.176.ftz\")\n",
"\n",
"\n",
"def detect_language(text: str) -> dict:\n",
" language = model.predict(text)[0][0].replace('__label__', '')\n",
" language = model.predict(text)[0][0].replace(\"__label__\", \"\")\n",
" print(language)\n",
" return {\"text\": text, \"language\": language}\n",
"\n",
"chain = (\n",
" runnable.RunnableLambda(detect_language)\n",
" | (lambda x: anonymizer.anonymize(x[\"text\"], language=x[\"language\"]))\n",
")\n"
"\n",
"chain = runnable.RunnableLambda(detect_language) | (\n",
" lambda x: anonymizer.anonymize(x[\"text\"], language=x[\"language\"])\n",
")"
]
},
{
Expand Down
Loading
Loading