### Start UralicNLP MCP Server for LLM Tool Use Source: https://context7.com/mikahama/uralicnlp/llms.txt Starts an HTTP MCP server on localhost:8000, exposing UralicNLP's morphological and dictionary tools for LLM integration. Requires Python to be installed. ```bash # Start the MCP server (listens on http://localhost:8000/mcp) python -m uralicNLP.uralicMCP ``` -------------------------------- ### Install HFST or HFST-DEV Source: https://github.com/mikahama/uralicnlp/wiki/Home Alternative installation methods for HFST or HFST-DEV, which can also be used with UralicNLP. ```bash pip install hfst ``` ```bash pip install hfst-dev ``` -------------------------------- ### Install uralicNLP Source: https://github.com/mikahama/uralicnlp/blob/master/README.md Install the UralicNLP library using pip. If Constraint Grammar features are needed, VISL CG-3 must also be installed. ```bash pip install uralicNLP ``` -------------------------------- ### Install uralicNLP and optional extras Source: https://context7.com/mikahama/uralicnlp/llms.txt Install the core library from PyPI. Optional extras provide full FST support, neural morphology fallback, semantic clustering, and LLM integrations. ```bash pip install uralicNLP # Optional extras pip install hfst # For full FST support (Apertium transducers, get_all_forms) pip install natas # For neural morphology fallback pip install scikit-learn numpy # For semantic clustering pip install openai # For ChatGPT LLM support pip install google-generativeai # For Gemini LLM support pip install mistralai # For Mistral LLM support pip install anthropic # For Claude LLM support pip install pymongo # For fast MongoDB dictionary backend ``` -------------------------------- ### Install Dependencies with Pip Source: https://github.com/mikahama/uralicnlp/blob/master/LLM-skill/uralicnlp-skill-template/SKILL.md Run this command to install the necessary Python packages for UralicNLP. Use this if imports fail or it's the first run in a session. ```bash python -m pip install -r scripts/requirements.txt ``` -------------------------------- ### Example MCP Client Configuration for LLMs Source: https://context7.com/mikahama/uralicnlp/llms.txt Example JSON configuration for an MCP client, such as Claude Desktop, to connect to the UralicNLP MCP server. ```json // Example MCP client configuration (e.g., Claude Desktop config.json) { "mcpServers": { "uralicNLP": { "url": "http://localhost:8000/mcp", "transport": "streamable-http" } } } ``` -------------------------------- ### Install Pyhfst with Cython Support Source: https://github.com/mikahama/uralicnlp/wiki/Home Install Pyhfst with Cython for faster processing. This is a prerequisite for optimizing UralicNLP's performance. ```bash pip install cython ``` ```bash pip install --upgrade --force-reinstall pyhfst --no-cache-dir ``` -------------------------------- ### Start UralicMCP Server Source: https://github.com/mikahama/uralicnlp/wiki/UralicMCP Run this command in your terminal to start the MCP server. It will output the port it is listening on, typically http://localhost:8000/mcp. ```python python -m uralicNLP.uralicMCP ``` -------------------------------- ### Download Models for a Language Source: https://github.com/mikahama/uralicnlp/wiki/Models Downloads all available models for a specified language. Run with sudo for system-wide installation. ```python from uralicNLP import uralicApi euralicApi.download("fin") ``` -------------------------------- ### Download SemFi Models in Python Source: https://github.com/mikahama/uralicnlp/wiki/SemFi,-SemUr-(legacy-stuff) Import the semfi library and use the download function to get the Finnish semantic databases. ```python from uralicNLP import semfi semfi.download("fin") ``` -------------------------------- ### Basic Prompt and Embed Usage Source: https://github.com/mikahama/uralicnlp/wiki/Large-Language-Models Demonstrates the fundamental usage of the LLM object for prompting and generating embeddings. This serves as a general example before specific model configurations. ```python llm.prompt("my fancy prompt") >>"Result from LLM" llm.embed("My great sentence") >>[-0.1803697, 1.1973963, 0.5283669, 1.5049516, -0.27077377...] ``` -------------------------------- ### Inspect Model Metadata with uralicApi.model_info Source: https://context7.com/mikahama/uralicnlp/llms.txt Prints citation and metadata for the FST/CG models installed for a given language. ```python from uralicNLP import uralicApi uralicApi.model_info("fin") # Prints JSON metadata including source repository, license, citation info ``` -------------------------------- ### Get Model Base Folders Source: https://github.com/mikahama/uralicnlp/wiki/Models Prints a list of directories where UralicNLP looks for models. Custom models can be placed in subdirectories named by language code. ```python from uralicNLP import uralicApi print uralicApi.__model_base_folders() ``` -------------------------------- ### Run Turku Neural Parser Docker Source: https://github.com/mikahama/uralicnlp/wiki/Dependency-parsing Starts the Turku Neural Parser in detached mode. This parser is slower but uses the latest neural models. ```bash docker run -d -p 9876:7689 turkunlp/turku-neural-parser:finnish-cpu-plaintext-server ``` -------------------------------- ### uralicApi.model_info Source: https://context7.com/mikahama/uralicnlp/llms.txt Displays citation and metadata for the FST/CG models installed for a specified language. ```APIDOC ## `uralicApi.model_info` — Inspect model metadata Prints citation and metadata for the FST/CG models installed for a given language. ### Usage ```python from uralicNLP import uralicApi uralicApi.model_info("fin") ``` ``` -------------------------------- ### Download and Import Dictionary Data for MongoDB Source: https://github.com/mikahama/uralicnlp/wiki/Dictionaries Downloads dictionary data for a specified language code and imports it into the MongoDB backend. Requires MongoDB and pymongo to be installed. ```python from uralicNLP import uralicApi uralicApi.download("kpv") #Download the latest dictionary data uralicApi.import_dictionary_to_db("kpv") #Update the MongoDB with the new data ``` -------------------------------- ### Run Turku Statistical Parser Docker Source: https://github.com/mikahama/uralicnlp/wiki/Dependency-parsing Starts the Turku Statistical Parser in detached mode with automatic restarts. This parser is faster. ```bash docker run --restart always -d -p 0.0.0.0:9876:9876 kazhar/finnish-dep-parser ``` -------------------------------- ### List Supported Languages for SemFi Source: https://github.com/mikahama/uralicnlp/wiki/SemFi,-SemUr-(legacy-stuff) Call semfi.supported_languages() to get a list of languages for which SemFi models are available. ```python semfi.supported_languages() ``` -------------------------------- ### Foma Phonological Rule Application Output Source: https://github.com/mikahama/uralicnlp/blob/master/uralicNLP/foma/README.md Example output from running a Foma script with phonrule.py, showing the input word transformed through sequential rules with rule names and descriptions. ```text cad[ARule|Rule one]cbd[BRule|Rule two]ccd ``` -------------------------------- ### Uninstall Models for a Language Source: https://github.com/mikahama/uralicnlp/wiki/Models Removes all downloaded models for a specified language to free up space or manage installations. ```python from uralicNLP import uralicApi euralicApi.uninstall("fin") ``` -------------------------------- ### Get Model Information Source: https://github.com/mikahama/uralicnlp/wiki/Models Retrieves and displays information about the FSTs and CGs for a given language, including license and authors. ```python from uralicNLP import uralicApi euralicApi.model_info("fin") ``` -------------------------------- ### uralicMCP — MCP server for LLM tool use Source: https://context7.com/mikahama/uralicnlp/llms.txt Starts an HTTP MCP server that exposes UralicNLP's morphological and dictionary tools, allowing MCP-compatible LLMs to call them directly. ```APIDOC ## `uralicMCP` — MCP server for LLM tool use Starts an HTTP MCP server exposing UralicNLP's morphological and dictionary tools so that any MCP-compatible LLM (Claude, Jan.ai, etc.) can call them directly. ### Starting the server ```bash # Start the MCP server (listens on http://localhost:8000/mcp) python -m uralicNLP.uralicMCP ``` ### Example client configuration ```json // Example MCP client configuration (e.g., Claude Desktop config.json) { "mcpServers": { "uralicNLP": { "url": "http://localhost:8000/mcp", "transport": "streamable-http" } } } ``` The server exposes tools for morphological analysis, generation, lemmatization, segmentation, and dictionary lookup — enabling an LLM to query endangered language grammars on demand. ``` -------------------------------- ### Constraint Grammar Disambiguation with cg3.Cg3 Source: https://context7.com/mikahama/uralicnlp/llms.txt Rule-based morphological disambiguation using VISL CG-3. Requires CG-3 to be installed on the system. ```python from uralicNLP.cg3 import Cg3, Cg3Pipe from uralicNLP import tokenizer # Single-language CG disambiguation sentence = "Kissa voi nauraa" tokens = tokenizer.words(sentence) cg = Cg3("fin") disambiguated = cg.disambiguate(tokens) # >> [(u'Kissa', []), # (u'voi', []), ``` -------------------------------- ### Generate All Inflectional Forms with uralicApi.get_all_forms Source: https://context7.com/mikahama/uralicnlp/llms.txt Generates every inflected form of a lemma given its part-of-speech tag. Useful for building training datasets. Requires `pip install hfst`. ```python from uralicNLP import uralicApi # All forms of Finnish noun "kissa" forms = uralicApi.get_all_forms("kissa", "N", "fin") # >> [('kissa+N+Sg+Nom', 0.0), ('kissaa+N+Sg+Par', 0.0), ...] # With limits and custom tag filters forms = uralicApi.get_all_forms( "kissa", "N", "fin", descriptive=False, limit_forms=20, filter_out=["#", "+Der", "+Cmp", "+Err"] ) ``` -------------------------------- ### Query Dictionary with MongoDB Backend Source: https://github.com/mikahama/uralicnlp/wiki/Dictionaries Performs dictionary queries using the MongoDB backend for faster lookups. Ensure MongoDB and pymongo are installed and the dictionary data is imported. ```python from uralicNLP import uralicApi from uralicNLP.dictionary_backends import MongoDictionary uralicApi.dictionary_lemmas("sms",backend=MongoDictionary) uralicApi.dictionary_search("car", "sms",backend=MongoDictionary) ``` -------------------------------- ### Get Word Information by Lemma and POS Source: https://github.com/mikahama/uralicnlp/wiki/SemFi,-SemUr-(legacy-stuff) Retrieve detailed information about a specific word, including its lemma, part-of-speech, frequency, and unique ID. Requires the word, its POS tag, and the language code. ```python semfi.get_word("kissa","N", "fin") ``` -------------------------------- ### Generate All Inflectional Forms Source: https://github.com/mikahama/uralicnlp/wiki/Neural-morphology Use `uralicApi.get_all_forms` to generate all possible inflectional forms for a given lemma, part of speech, and language. Optional arguments include `descriptive`, `limit_forms`, and `filter_out` for customization. Ensure `hfst-dev` is installed if you encounter errors. ```python from uralicNLP import uralicApi uralicApi.get_all_forms("kissa", "N", "fin") ``` -------------------------------- ### Initialize Gemini for Prompting Source: https://github.com/mikahama/uralicnlp/wiki/Large-Language-Models Initializes the Gemini LLM for text generation. Requires the 'google-generativeai' library and an API key obtained from AI Studio. Specify the desired model, e.g., 'gemini-1.5-flash'. ```python from uralicNLP.llm import get_llm llm = get_llm("gemini", "YOUR API KEY", model="gemini-1.5-flash") llm.prompt("What is Erzya?") >>"Erzya is a **Finno-Ugric language** and the **cultural identity** of the **Erzya people**, one of the two main groups within the Mordvinic people. ..." ``` -------------------------------- ### Initialize Mistral for Prompting Source: https://github.com/mikahama/uralicnlp/wiki/Large-Language-Models Initializes the Mistral LLM for text generation. Requires the 'mistralai' library and an API key. Specify the desired model, e.g., 'mistral-small-latest'. ```python from uralicNLP.llm import get_llm llm = get_llm("mistral", "YOUR API KEY", model="mistral-small-latest") llm.prompt("What is Komi-Zyrian?") >>"Komi-Zyrian, often simply referred to as Komi, is a Uralic language spoken in the Komi Republic and some other regions of Russia. ..." ``` -------------------------------- ### Get translation Source: https://github.com/mikahama/uralicnlp/blob/master/README.md Retrieves translations for minority language words into multiple target languages. ```APIDOC ## get_translation ### Description Retrieves translations for a given word from a minority language into various other languages. ### Method `uralicApi.get_translation(word, source_lang)` ### Parameters - **word** (string) - The word to translate. - **source_lang** (string) - The ISO 639-3 code of the source language. ### Request Example ```python from uralicNLP import uralicApi print(uralicApi.get_translation("piânnai", "sms")) ``` ### Response #### Success Response - **dictionary**: Keys are ISO 639-3 language codes, and values are lists of translated words. ``` -------------------------------- ### iso_to_name Source: https://github.com/mikahama/uralicnlp/wiki/uralicNLP.string_processing Converts a language ISO code to its English name. For example, 'kpv' is converted to 'Komi-Zyrian'. ```APIDOC ## iso_to_name ### Description Returns the English name for the language ISO code. ### Method `string_processing.iso_to_name(iso_code: str) -> str` ### Parameters #### Path Parameters - **iso_code** (str) - Required - The language ISO code (e.g., "kpv"). ### Response #### Success Response (200) - **language_name** (str) - The English name of the language. ### Request Example ```python from uralicNLP import string_processing string_processing.iso_to_name("kpv") ``` ### Response Example ```json { "language_name": "Komi-Zyrian" } ``` ``` -------------------------------- ### Initialize ChatGPT for Prompting Source: https://github.com/mikahama/uralicnlp/wiki/Large-Language-Models Initializes the ChatGPT LLM for text generation. Requires the 'openai' library and an API key. Specify the desired model, e.g., 'gpt-4o'. ```python from uralicNLP.llm import get_llm llm = get_llm("chatgpt", "YOUR API KEY", model="gpt-4o") llm.prompt("What is Skolt Sami?") >>"Skolt Sami is a Uralic, Sami language spoken by the Skolt Sami people, a small indigenous Finno-Ugric ethnic group ..." ``` -------------------------------- ### cg3.Cg3.disambiguate Source: https://context7.com/mikahama/uralicnlp/llms.txt Performs rule-based morphological disambiguation using VISL CG-3. Requires CG-3 to be installed on the system. ```APIDOC ## `cg3.Cg3` — Constraint Grammar disambiguation Rule-based morphological disambiguation using VISL CG-3. Requires CG-3 to be installed on the system. ### Usage ```python from uralicNLP.cg3 import Cg3, Cg3Pipe from uralicNLP import tokenizer # Single-language CG disambiguation sentence = "Kissa voi nauraa" tokens = tokenizer.words(sentence) cg = Cg3("fin") disambiguated = cg.disambiguate(tokens) ``` ``` -------------------------------- ### Download SemFi Models via Command Line Source: https://github.com/mikahama/uralicnlp/wiki/SemFi,-SemUr-(legacy-stuff) Use this command to download the Finnish SemFi models from the command line. ```bash python -m uralicNLP.download --languages fin --semfi ``` -------------------------------- ### Download Models Source: https://github.com/mikahama/uralicnlp/wiki/SemFi,-SemUr-(legacy-stuff) Instructions for downloading SemFi and SemUr models using the command line or Python script. ```APIDOC ## Download Models On command line: ```bash python -m uralicNLP.download --languages fin --semfi ``` Use the following script to download the semantic databases in Python: ```python from uralicNLP import semfi semfi.download("fin") ``` Use `semfi.supported_languages()` to list the supported languages. ``` -------------------------------- ### Get Translation from Skolt Sami to Finnish Source: https://github.com/mikahama/uralicnlp/wiki/Dictionaries Finds translations for a given word from the Skolt Sami dictionary into Finnish. ```python from uralicNLP import uralicApi uralicApi.get_translation("piânnai", "sms", "fin") >> ['koira'] ``` -------------------------------- ### Mistral Integration Source: https://github.com/mikahama/uralicnlp/wiki/Large-Language-Models How to initialize and use the Mistral model via UralicNLP. ```APIDOC ## Mistral Integration To use Mistral, you need to `pip install mistralai`. ### Initialization for Prompting ```python from uralicNLP.llm import get_llm llm = get_llm("mistral", "YOUR API KEY", model="mistral-small-latest") ``` ### Initialization for Embeddings ```python from uralicNLP.llm import get_llm llm = get_llm("mistral", "YOUR API KEY", model="mistral-embed") ``` ### Usage ```python # For prompting llm.prompt("What is Komi-Zyrian?") # >>"Komi-Zyrian, often simply referred to as Komi, is a Uralic language spoken in the Komi Republic and some other regions of Russia. ..." # For embeddings llm.embed("My great sentence") # >>[-0.1803697, 1.1973963, 0.5283669, 1.5049516, -0.27077377...] ``` ``` -------------------------------- ### Gemini Integration Source: https://github.com/mikahama/uralicnlp/wiki/Large-Language-Models How to initialize and use the Gemini model via UralicNLP. ```APIDOC ## Gemini Integration To use Gemini, you need to `pip install google-generativeai`. [Get the API key from AI Studio](https://aistudio.google.com/app/apikey). ### Initialization for Prompting ```python from uralicNLP.llm import get_llm llm = get_llm("gemini", "YOUR API KEY", model="gemini-1.5-flash") ``` ### Initialization for Embeddings ```python from uralicNLP.llm import get_llm llm = get_llm("gemini", "YOUR API KEY", model="models/text-embedding-004") ``` ### Optional Parameters Optionally, you can provide `task_type` to `get_llm()`. The default value is `task_type="retrieval_document"`. ### Usage ```python # For prompting llm.prompt("What is Erzya?") # >>"Erzya is a **Finno-Ugric language** and the **cultural identity** of the **Erzya people**, one of the two main groups within the Mordvinic people. ..." # For embeddings llm.embed("My great sentence") # >>[-0.1803697, 1.1973963, 0.5283669, 1.5049516, -0.27077377...] ``` ``` -------------------------------- ### ChatGPT Integration Source: https://github.com/mikahama/uralicnlp/wiki/Large-Language-Models How to initialize and use the ChatGPT model via UralicNLP. ```APIDOC ## ChatGPT Integration To use ChatGPT, you need to `pip install openai`. ### Initialization for Prompting ```python from uralicNLP.llm import get_llm llm = get_llm("chatgpt", "YOUR API KEY", model="gpt-4o") ``` ### Initialization for Embeddings ```python from uralicNLP.llm import get_llm llm = get_llm("chatgpt", "YOUR API KEY", model="text-embedding-3-small") ``` ### Usage ```python # For prompting llm.prompt("What is Skolt Sami?") # >>"Skolt Sami is a Uralic, Sami language spoken by the Skolt Sami people, a small indigenous Finno-Ugric ethnic group ..." # For embeddings llm.embed("My great sentence") # >>[-0.1803697, 1.1973963, 0.5283669, 1.5049516, -0.27077377...] ``` ``` -------------------------------- ### Initialize Local Hugging Face Model for Prompting Source: https://github.com/mikahama/uralicnlp/wiki/Large-Language-Models Initializes a local LLM from Hugging Face for text generation. Requires the 'transformers' library. Specify the model name, e.g., 'microsoft/Phi-3.5-mini-instruct', and optionally 'max_length'. ```python from uralicNLP.llm import get_llm llm = get_llm("microsoft/Phi-3.5-mini-instruct", max_length=20) llm.prompt("What is Livonian?") >>"What is Livonian? Livonian is an extinct Finnic language that was histor" ``` -------------------------------- ### Get Translation Source: https://github.com/mikahama/uralicnlp/wiki/Dictionaries Finds translations for a given word from a source language dictionary to a target language. The target language is optional. ```APIDOC ## get_translation ### Description Retrieves translations for a given word from a specified dictionary, optionally to a target language. ### Method `uralicApi.get_translation(word, source_lang_code, target_lang_code=None, backend=None)` ### Parameters - **word** (string) - The word to translate. - **source_lang_code** (string) - The language code of the dictionary containing the word (e.g., 'sms'). - **target_lang_code** (string, optional) - The language code of the desired translation (e.g., 'fin'). If not provided, translations in multiple languages are returned. - **backend** (optional) - The dictionary backend to use. ### Response Example (with target_lang_code) ```json [ "koira" ] ``` ### Response Example (without target_lang_code) ```json { "sme": [ "beana" ], "sjd": [ "пе̄ннэ" ], "sju": [ "biegˈŋja", "dä̀rra" ], "rus": [ "собака" ], "nob": [ "hund" ], "eng": [ "dog" ], "deu": [ "Hund" ], "fin": [ "koira" ] } ``` ``` -------------------------------- ### Configure Device for Local Models Source: https://github.com/mikahama/uralicnlp/wiki/Large-Language-Models Demonstrates how to specify the device for local LLM inference. By default, CPU is used (device=-1). Use device=1 for the first CUDA GPU. ```python llm = get_llm("microsoft/Phi-3.5-mini-instruct", device=1) ``` -------------------------------- ### Get Supported Languages Source: https://github.com/mikahama/uralicnlp/wiki/Machine-Translation Call the get_languages() method on a translator object to retrieve a dictionary of supported source and target languages. ```python translator.get_languages() >> {u'est': [u'est_estspell', u'est_estgram'], u'nob': [u'fao'], u'smn': [u'fin', u'sme'], u'fao': [u'nno', u'fao_faospell', u'fao_faogram', u'nob'], u'sme': [u'fin', u'sme_smespell', u'sma', u'sme_smegram', u'nob', u'smj', u'smn'], u'fin': [u'sme', u'smn', u'fin_fingram', u'fin_finspell'], u'sma': [u'sme', u'sma_smagram', u'nob', u'sma_smaspell'], u'smj': [u'nob', u'sme', u'smj_smjgram', u'smj_smjspell']} ``` -------------------------------- ### Download language models Source: https://context7.com/mikahama/uralicnlp/llms.txt Download FST, CG, dictionary, and neural model files for a language to `~/.uralicnlp//`. This function can also be invoked from the command line. ```python from uralicNLP import uralicApi # Download Finnish and Skolt Sami models uralicApi.download("fin") uralicApi.download("sms") # Check if a language is installed print(uralicApi.is_language_installed("fin")) # True ``` ```bash # Command-line download for multiple languages at once python -m uralicNLP.download --languages fin eng ara sme ``` -------------------------------- ### Local Models (Hugging Face) Integration Source: https://github.com/mikahama/uralicnlp/wiki/Large-Language-Models How to initialize and use local models from Hugging Face via UralicNLP. ```APIDOC ## Local Models (Hugging Face) Integration To use models from Hugging Face, you need to `pip install transformers`. ### Initialization for Prompting ```python from uralicNLP.llm import get_llm llm = get_llm("microsoft/Phi-3.5-mini-instruct", max_length=20) ``` ### Initialization for Embeddings ```python from uralicNLP.llm import get_llm llm = get_llm("microsoft/Phi-3.5-mini-instruct") ``` ### Optional Parameters It is possible to pass `device` to `get_llm()`. `device=1` would use the first CUDA device. By default, the value is `device=-1`, which uses CPU. ### Usage ```python # For prompting llm.prompt("What is Livonian?") # >>"What is Livonian? Livonian is an extinct Finnic language that was histor" # For embeddings llm.embed("My great sentence") # >>[-0.1803697, 1.1973963, 0.5283669, 1.5049516, -0.27077377...] ``` ``` -------------------------------- ### Initialize Claude for Prompting Source: https://github.com/mikahama/uralicnlp/wiki/Large-Language-Models Initializes the Claude LLM for text generation. Requires the 'anthropic' library and an API key. Note that Claude models do not support embeddings. Specify the desired model, e.g., 'claude-3-5-sonnet-latest'. ```python from uralicNLP.llm import get_llm llm = get_llm("claude", "YOUR API KEY", model="claude-3-5-sonnet-latest") llm.prompt("What is Tundra Nenets?") >>"Tundra Nenets is an indigenous Samoyedic language spoken by the Nenets people in northern Russia, primarily in the Yamalo-Nenets ..." ``` -------------------------------- ### Multilingual and Piped CG3 Analyzers Source: https://context7.com/mikahama/uralicnlp/llms.txt Demonstrates how to use Cg3 for multilingual analysis by combining languages and how to chain multiple CG analyzers sequentially using Cg3Pipe. ```python cg_multi = Cg3("fin", morphology_languages=["fin", "olo"]) cg_multi.disambiguate(["Kissa", "on", "kotona", "."], language_flags=True) ``` ```python cg1 = Cg3("fin") cg2 = Cg3("olo") pipe = Cg3Pipe(cg1, cg2) pipe.disambiguate(["Kissa", "on", "kotona", "."]) ``` -------------------------------- ### Get translations for minority language words Source: https://github.com/mikahama/uralicnlp/blob/master/README.md Retrieves translations for a given word in a minority language into multiple other languages. Requires the word and its ISO language code. ```python from uralicNLP import uralicApi uralicApi.get_translation("piânnai", "sms") >> {'sme': ['beana'], 'sjd': ['пе̄ннэ'], 'sju': ['biegˈŋja', 'dä̀rra'], 'rus': ['собака'], 'nob': ['hund'], 'eng': ['dog'], 'deu': ['Hund'], 'fin': ['koira']} ``` -------------------------------- ### Initialize ChatGPT for Embeddings Source: https://github.com/mikahama/uralicnlp/wiki/Large-Language-Models Initializes the ChatGPT LLM for generating embeddings. Requires the 'openai' library and an API key. Use a model suitable for embeddings, such as 'text-embedding-3-small'. ```python from uralicNLP.llm import get_llm llm = get_llm("chatgpt", "YOUR API KEY", model="text-embedding-3-small") llm.embed("My great sentence") >>[-0.1803697, 1.1973963, 0.5283669, 1.5049516, -0.27077377...] ``` -------------------------------- ### Use Custom Transducer Files Source: https://github.com/mikahama/uralicnlp/wiki/Models Enables the use of your own transducer files by specifying their path. This applies to generation, analysis, and lemmatization. ```python from uralicNLP import uralicApi euralicApi.generate("kissa+N+Pl+Nom", "fin", filename="/path_to_your/transducer.hfstol") euralicApi.analyze("kissat", "fin", filename="/path_to_your/transducer.hfstol") euralicApi.lemmatize("kissat", "fin", filename="/path_to_your/transducer.hfstol") ``` -------------------------------- ### Convert Language ISO Code to English Name Source: https://github.com/mikahama/uralicnlp/wiki/uralicNLP.string_processing Use this function to get the English name for a given language ISO code. Requires importing the string_processing module. ```python from uralicNLP import string_processing string_processing.iso_to_name("kpv") >> Komi-Zyrian ``` -------------------------------- ### Initialize Local Hugging Face Model for Embeddings Source: https://github.com/mikahama/uralicnlp/wiki/Large-Language-Models Initializes a local LLM from Hugging Face for generating embeddings. Requires the 'transformers' library. Specify the model name, e.g., 'microsoft/Phi-3.5-mini-instruct'. ```python from uralicNLP.llm import get_llm llm = get_llm("microsoft/Phi-3.5-mini-instruct") llm.embed("My great sentence") >>[-0.1803697, 1.1973963, 0.5283669, 1.5049516, -0.27077377...] ``` -------------------------------- ### Get Word Information with Homonyms Source: https://github.com/mikahama/uralicnlp/wiki/SemFi,-SemUr-(legacy-stuff) Find all entries for a given word, including homonyms, without specifying the part-of-speech. Returns a list of dictionaries, each containing word details. ```python semfi.get_words("kuusi", "fin") ``` -------------------------------- ### Parse CoNLL-U to UD Collection Source: https://github.com/mikahama/uralicnlp/wiki/UD-parser Initialize a UD collection by opening a CoNLL-U formatted file. Ensure the file is opened with UTF-8 encoding. ```python from uralicNLP.ud_tools import UD_collection ud = UD_collection(codecs.open("file.conllu", encoding="utf-8")) ``` -------------------------------- ### General LLM Usage Source: https://github.com/mikahama/uralicnlp/wiki/Large-Language-Models Demonstrates the basic usage of the `llm` object for prompting and generating embeddings. ```APIDOC ## General LLM Usage This shows the fundamental methods available on an LLM object obtained through UralicNLP. ### Method - `prompt(text: str)`: Sends a text prompt to the LLM and returns the response. - `embed(text: str)`: Generates an embedding vector for the given text. ### Request Example ```python # Assuming 'llm' is an initialized LLM object llm.prompt("my fancy prompt") # >>"Result from LLM" llm.embed("My great sentence") # >>[-0.1803697, 1.1973963, 0.5283669, 1.5049516, -0.27077377...] ``` ``` -------------------------------- ### Lemmatize a word form Source: https://context7.com/mikahama/uralicnlp/llms.txt Get a deduplicated list of possible lemmas for a word form. Optionally mark compound word boundaries with `|`. Supports neural fallback for out-of-vocabulary words. ```python from uralicNLP import uralicApi # Erzya lemmatization uralicApi.lemmatize("вирев", "myv") # >> ['вирев', 'вирь'] # Finnish with compound boundary marking uralicApi.lemmatize("luutapiiri", "fin", word_boundaries=True) # >> ['luuta|piiri', 'luu|tapiiri'] # English lemmatization uralicApi.lemmatize("running", "eng") # >> ['run'] # Neural fallback for OOV words uralicApi.lemmatize("nirhautan", "fin", neural_fallback=True) # >> ['nirhauttaa'] ``` -------------------------------- ### Rule-based Disambiguation with CG3 Source: https://github.com/mikahama/uralicnlp/wiki/Disambiguation Disambiguate sentences using VISL CG-3. This requires installing CG-3. The output is a list of tuples, where each tuple contains the word form and a list of possible disambiguations. ```python from uralicNLP.cg3 import Cg3 from uralicNLP import tokenizer sentence = "Kissa voi nauraa" tokens = tokenizer.words(sentence) cg = Cg3("fin") print(cg.disambiguate(tokens)) >>[(u'Kissa', [>, >]), (u'voi', [>]), (u'nauraa', [>])] ``` ```python disambiguations = cg.disambiguate(tokens) for disambiguation in disambiguations: possible_words = disambiguation[1] for possible_word in possible_words: print(possible_word.lemma, possible_word.morphology) >>Kissa [u'N', u'Prop', u'Sg', u'Nom', u''] >>kissa [u'N', u'Sg', u'Nom', u''] >>voida [u'V', u'Act', u'Ind', u'Prs', u'Sg3', u''] >>nauraa [u'V', u'Act', u'InfA', u'Sg', u'Lat', u''] ``` -------------------------------- ### Initialize Mistral for Embeddings Source: https://github.com/mikahama/uralicnlp/wiki/Large-Language-Models Initializes the Mistral LLM for generating embeddings. Requires the 'mistralai' library and an API key. Use a model suitable for embeddings, such as 'mistral-embed'. ```python from uralicNLP.llm import get_llm llm = get_llm("mistral", "YOUR API KEY", model="mistral-embed") llm.embed("My great sentence") >>[-0.1803697, 1.1973963, 0.5283669, 1.5049516, -0.27077377...] ``` -------------------------------- ### Get Translations from Skolt Sami Dictionary (Optional Target Language) Source: https://github.com/mikahama/uralicnlp/wiki/Dictionaries Retrieves translations for a word from the Skolt Sami dictionary. If no target language is specified, translations in multiple languages are returned. ```python from uralicNLP import uralicApi uralicApi.get_translation("piânnai", "sms") >> {'sme': ['beana'], 'sjd': ['пе̄ннэ'], 'sju': ['biegˈŋja', 'dä̀rra'], 'rus': ['собака'], 'nob': ['hund'], 'eng': ['dog'], 'deu': ['Hund'], 'fin': ['koira']} ``` -------------------------------- ### Finnish Dependency Parsing with Turku Neural Parser Source: https://context7.com/mikahama/uralicnlp/llms.txt Parses Finnish text into Universal Dependencies structures. Requires Docker running and the Turku Neural Parser server to be accessible. ```python from uralicNLP import dependency # Requires Docker running: # docker run -d -p 9876:7689 turkunlp/turku-neural-parser:finnish-cpu-plaintext-server ud = dependency.parse_text("kissa nauroi kovaa\nLehmä lauloi ainiaan", "fin") for sentence in ud: for word in sentence: print(word.pos, word.lemma, word.get_attribute("deprel")) print("---") # >> NOUN kissa nsubj # >> VERB nauraa root # >> ADJ kova obj # >> --- # >> NOUN lehmä nsubj # >> VERB laulaa root # >> ADV ainiaan advmod # Custom parser URL ud = dependency.parse_text("kissa nauroi", "fin", url="http://localhost:9876") ``` -------------------------------- ### Enable Neural Fallback in UralicNLP Source: https://github.com/mikahama/uralicnlp/wiki/Neural-morphology Pass `neural_fallback=True` to functions like `generate`, `analyze`, or `lemmatize` to utilize the neural model for out-of-vocabulary words. The `n_best` parameter can be increased to get more candidates, which is useful for homonyms. ```python from uralicNLP import uralicApi uralicApi.generate("koirailla+V+Act+Ind+Prs+Sg1", "fin", neural_fallback=True) >> [('koirailen', -0.0015927295899018645)] ``` ```python from uralicNLP import uralicApi uralicApi.analyze("hörpähdin", "fin", neural_fallback=True) >> [('hörpähtää+V+Act+Ind+Prt+Sg1', -0.27097199857234955)] ``` ```python from uralicNLP import uralicApi uralicApi.lemmatize("nirhautan", "fin", neural_fallback=True) >> ['nirhauttaa'] ``` -------------------------------- ### Voyage AI Integration Source: https://github.com/mikahama/uralicnlp/wiki/Large-Language-Models How to initialize and use the Voyage AI model via UralicNLP. Note: Voyage AI does not support prompting. ```APIDOC ## Voyage AI Integration To use Voyage AI, you need to `pip install voyageai`. Please notice that this model does not support prompting. ### Initialization ```python from uralicNLP.llm import get_llm llm = get_llm("voyage", "YOUR API KEY", model="voyage-3") ``` ### Usage ```python llm.embed("My great sentence") # >>[-0.1803697, 1.1973963, 0.5283669, 1.5049516, -0.27077377...] ``` ``` -------------------------------- ### Get All Syntactic Relations for a Word Source: https://github.com/mikahama/uralicnlp/wiki/SemFi,-SemUr-(legacy-stuff) Retrieve all syntactic relations associated with a given word. The results can be sorted by frequency if `sort=True` is specified. Requires the word's information (obtained via `get_word`) and the language code. ```python word = semfi.get_word("näätä","N", "fin") semfi.get_all_relations(word, "fin", sort=True) #lists all related words ``` -------------------------------- ### Run Foma Phonological Rules with phonrule.py Source: https://github.com/mikahama/uralicnlp/blob/master/uralicNLP/foma/README.md Execute a Foma script using the phonrule.py utility. This tool traces rule applications and shows decorated output to STDOUT. ```bash $echo "cad" | python phonrule.py myscript.foma ``` -------------------------------- ### Get Words by Specific Syntactic Relation Source: https://github.com/mikahama/uralicnlp/wiki/SemFi,-SemUr-(legacy-stuff) Find words that have a specific syntactic relation to a given word. The results can be sorted by frequency using `sort=True`. Requires the word's information, the relation type, and the language code. ```python word = semfi.get_word("näätä","N", "fin") semfi.get_by_relation(word, "dobj", "fin", sort=True) #lists words with a given syntactic relation ``` -------------------------------- ### Initialize Voyage AI for Embeddings Source: https://github.com/mikahama/uralicnlp/wiki/Large-Language-Models Initializes the Voyage AI LLM for generating embeddings. Requires the 'voyageai' library and an API key. Note that Voyage AI models do not support prompting. Specify the desired model, e.g., 'voyage-3'. ```python from uralicNLP.llm import get_llm llm = get_llm("voyage", "YOUR API KEY", model="voyage-3") llm.embed("My great sentence") >>[-0.1803697, 1.1973963, 0.5283669, 1.5049516, -0.27077377...] ``` -------------------------------- ### uralicApi.download Source: https://context7.com/mikahama/uralicnlp/llms.txt Downloads language models (FST, CG, dictionary, neural) for specified languages to the local `~/.uralicnlp/` directory. Can also be used via the command line. ```APIDOC ## uralicApi.download — Download language models ### Description Downloads FST, CG, dictionary, and neural model files for a language to `~/.uralicnlp//`. Can also be invoked from the command line. ### Method ```python from uralicNLP import uralicApi # Download Finnish and Skolt Sami models uralicApi.download("fin") uralicApi.download("sms") # Check if a language is installed print(uralicApi.is_language_installed("fin")) # True ``` ```bash # Command-line download for multiple languages at once python -m uralicNLP.download --languages fin eng ara sme ``` ``` -------------------------------- ### Morphological analysis of a word form Source: https://context7.com/mikahama/uralicnlp/llms.txt Analyze a word form to get possible readings (analysis strings with weights). Uses the descriptive FST by default; pass `descriptive=False` for normative analysis. Supports analyzing against multiple languages simultaneously. ```python from uralicNLP import uralicApi # Finnish word with multiple possible readings results = uralicApi.analyze("voita", "fin") # >> [['voi+N+Sg+Par', 0.0], ['voi+N+Pl+Par', 0.0], # ['voittaa+V+Act+Imprt+Sg2', 0.0], ...] # Normative analysis only results = uralicApi.analyze("voita", "fin", descriptive=False) # Erzya analysis results = uralicApi.analyze("ёртозь", "myv") # Analyze against multiple languages at once results = uralicApi.analyze("kissa", ["fin", "olo"]) # Neural fallback for out-of-vocabulary words (requires: pip install natas) results = uralicApi.analyze("hörpähdin", "fin", neural_fallback=True) # >> [('hörpähtää+V+Act+Ind+Prt+Sg1', -0.27097199857234955)] ``` -------------------------------- ### Lemmatization CLI Source: https://github.com/mikahama/uralicnlp/blob/master/LLM-skill/uralicnlp-skill-template/SKILL.md Use the CLI helper to lemmatize a given word. The output is in JSON format. ```bash python scripts/uralic_cli.py lemmatize --word mieʹcen ``` -------------------------------- ### Claude Integration Source: https://github.com/mikahama/uralicnlp/wiki/Large-Language-Models How to initialize and use the Claude model via UralicNLP. Note: Claude does not support embeddings. ```APIDOC ## Claude Integration To use Claude, you need to `pip install anthropic`. Please notice that this model does not support embeddings. ### Initialization ```python from uralicNLP.llm import get_llm llm = get_llm("claude", "YOUR API KEY", model="claude-3-5-sonnet-latest") ``` ### Usage ```python llm.prompt("What is Tundra Nenets?") # >>"Tundra Nenets is an indigenous Samoyedic language spoken by the Nenets people in northern Russia, primarily in the Yamalo-Nenets ..." ``` ``` -------------------------------- ### Download Language Models Source: https://github.com/mikahama/uralicnlp/blob/master/README.md Download language models for offline use from the command line or within Python code. This enables local processing for methods like generate(), analyze(), and lemmatize(). ```bash python -m uralicNLP.download --languages fin eng ``` ```python from uralicNLP import uralicApi euralicApi.download("fin") ```