### Setup local development environment for mlconjug3 Source: https://github.com/ars-linguistica/mlconjug3/blob/master/docs/contributing.html Commands to clone the repository, create a virtual environment, and install the package in development mode. ```bash git clone git@github.com:your_name_here/mlconjug3.git mkvirtualenv mlconjug3 cd mlconjug3/ python setup.py develop ``` -------------------------------- ### Install MLConjug3 from Source Source: https://github.com/ars-linguistica/mlconjug3/blob/master/docs/installation.html Clones the repository from GitHub and installs the package using the setup.py script. ```bash git clone git://github.com/Ars-Linguistica/mlconjug3 cd mlconjug3 python setup.py install ``` -------------------------------- ### Install mlconjug3 from Source Source: https://github.com/ars-linguistica/mlconjug3/blob/master/docs/installation.rst Instructions for cloning the repository or downloading the tarball and installing via setup.py or poetry. This is useful for developers or users requiring specific versions. ```shell git clone git://github.com/Ars-Linguistica/mlconjug3 cd mlconjug3 python setup.py install ``` ```shell curl -OL https://github.com/Ars-Linguistica/mlconjug3/tarball/master # Extract and run python setup.py install ``` ```shell pip install poetry poetry install ``` -------------------------------- ### Install Dependencies with Poetry Source: https://github.com/ars-linguistica/mlconjug3/blob/master/CONTRIBUTING.rst After cloning the repository, navigate into the project directory and use poetry to install all necessary project dependencies. Poetry is the recommended build manager for this project. ```shell cd mlconjug3 poetry install ``` -------------------------------- ### Install mlconjug3 from Source Source: https://github.com/ars-linguistica/mlconjug3/blob/master/INSTALL.rst Methods for cloning the repository or downloading the source tarball to perform a manual installation. This approach is useful for developers or those requiring specific versions. ```console git clone git://github.com/Ars-Linguistica/mlconjug3 cd mlconjug3 python setup.py install ``` ```console curl -OL https://github.com/Ars-Linguistica/mlconjug3/tarball/master # Extract and run setup.py ``` ```console pip install poetry poetry install ``` -------------------------------- ### CLI Configuration File Formats Source: https://context7.com/ars-linguistica/mlconjug3/llms.txt Examples of configuration files in TOML and YAML formats for persistent CLI settings and theme customization. ```APIDOC ## CLI Configuration File Create a TOML or YAML configuration file for persistent CLI settings and theme customization. ### TOML Configuration Example ```toml # config.toml - Place in ~/mlconjug3/config.toml for auto-loading # Language setting: fr, en, es, it, pt, ro language = "fr" # Subject format: "abbrev" or "pronoun" subject = "pronoun" # Output file path (optional) output = "conjugations.json" # File format: "json" or "csv" file_format = "json" # Rich table theme settings [theme] header_style = "bold #0D47A1" mood_style = "bold #F9A825" tense_style = "bold bright_magenta" person_style = "bold cyan" conjugation_style = "bold #4CAF50" ``` ### YAML Configuration Example ```yaml # config.yaml - Alternative YAML format language: "es" subject: "pronoun" output: "spanish_verbs.json" file_format: "json" theme: header_style: "bold blue" mood_style: "bold yellow" tense_style: "bold magenta" person_style: "bold cyan" conjugation_style: "bold green" ``` ``` -------------------------------- ### Using Configuration Files with mlconjug3 Source: https://github.com/ars-linguistica/mlconjug3/blob/master/docs/usage.rst Examples of using configuration files to manage settings for mlconjug3. You can use default paths or specify a custom path with the -c flag. ```console $ mlconjug3 -c hablar $ mlconjug3 -c /path/to/config.toml manger parler $ mlconjug3 -c /path/to/config.toml -l en -s pronoun -o conjugation_table.json -f json have ``` -------------------------------- ### Install MLConjug3 via pip Source: https://github.com/ars-linguistica/mlconjug3/blob/master/docs/installation.html Installs the most recent stable release of MLConjug3 using the Python package manager pip. ```bash pip install mlconjug3 ``` -------------------------------- ### Configuration File Formats Source: https://github.com/ars-linguistica/mlconjug3/blob/master/docs/usage.rst Examples of TOML and YAML configuration files for mlconjug3, allowing users to define language, output settings, and theme styles. ```toml language = "en" subject = "abbrev" output = "conjugation_table.json" file_format = "json" [theme] header_style = "bold #0D47A1" mood_style = "bold #F9A825" tense_style = "bold bright_magenta" person_style = "bold cyan" conjugation_style = "bold #4CAF50" ``` ```yaml language: fr subject: pronoun output: conjugation_table.json file_format: json theme: header_style: bold blue ``` -------------------------------- ### Command Line Interface (CLI) Usage Source: https://context7.com/ars-linguistica/mlconjug3/llms.txt Examples of using the mlconjug3 command-line tool for verb conjugation in different languages and output formats. ```APIDOC ## Command Line Interface (CLI) The CLI provides a rich terminal interface for conjugating verbs with formatted output tables and file export options. ### Usage Examples ```bash # Basic conjugation (French is default) mlconjug3 manger # Conjugate English verb with abbreviated subjects mlconjug3 -l en -s abbrev bring # Conjugate multiple French verbs with full pronouns mlconjug3 -l fr -s pronoun aimer être aller # Conjugate Spanish verb and save to JSON file mlconjug3 -l es -s pronoun hablar -o conjugation_table.json -f json # Conjugate Italian verbs and save to CSV mlconjug3 -l it -s abbrev parlare avere essere -o conjugations.csv -f csv # Use a configuration file mlconjug3 -c /path/to/config.toml manger # Override config file settings mlconjug3 -c /path/to/config.toml -l en -s pronoun -o output.json bring ``` ``` -------------------------------- ### Install mlconjug3 via Package Managers Source: https://github.com/ars-linguistica/mlconjug3/blob/master/INSTALL.rst Commands to install the stable release of mlconjug3 using standard Python package management tools. These methods are recommended for most users to ensure dependency resolution. ```console pip install mlconjug3 ``` ```console pipx install mlconjug3 ``` ```console conda config --add channels conda-forge conda config --set channel_priority strict conda install mlconjug3 ``` -------------------------------- ### Training a Custom Conjugation Model Source: https://context7.com/ars-linguistica/mlconjug3/llms.txt Guides on training a custom conjugation model using the `Model` class and then integrating it with the `Conjugator`. ```APIDOC ## Training a Custom Model ### Description This section details how to train a custom conjugation model using the `Model` class. It covers initializing components, preparing the dataset, training the model with training data, making predictions on a test set, and evaluating the model's accuracy. Finally, it shows how to use the trained custom model with the `Conjugator`. ### Method N/A (Code Example) ### Endpoint N/A (Code Example) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```python import mlconjug3 from mlconjug3 import Model, DataSet, Conjugator import numpy as np # Set random seed for reproducibility np.random.seed(42) # Initialize components language = 'fr' conjugator = Conjugator(language=language) # Create and prepare dataset dataset = DataSet(conjugator.conjug_manager.verbs) dataset.split_data(threshold=8, proportion=0.8) # Create model model = Model(language=language) # Train the model print("Training model...") model.train(dataset.train_input, dataset.train_labels) # Make predictions on test set predictions = model.predict(dataset.test_input) # Evaluate accuracy correct = sum(1 for p, l in zip(predictions, dataset.test_labels) if p == l) accuracy = correct / len(dataset.test_labels) print(f"Test accuracy: {accuracy:.2%}") # Use trained model with Conjugator conjugator.set_model(model) result = conjugator.conjugate('tester') print(f"\nConjugated 'tester' with custom model:") print(f" Template: {result.verb_info.template}") ``` ### Response #### Success Response (200) N/A (This is a code example, not an API response) #### Response Example ``` Training model... Test accuracy: 95.00% Conjugated 'tester' with custom model: Template: tester:er ``` ``` -------------------------------- ### Conjugating Verbs via CLI Source: https://github.com/ars-linguistica/mlconjug3/blob/master/docs/usage.rst Examples of using the mlconjug3 command line interface to conjugate verbs in various languages, with options for subject format, output file format, and destination files. ```console $ mlconjug3 -l en -s abbrev 'have' $ mlconjug3 -l fr -s pronoun 'aimer' 'être' 'aller' $ mlconjug3 -l es -s pronoun -f json 'hablar' -o 'conjugation_table.json' $ mlconjug3 -l it -s abbrev -f csv 'parlare' 'avere' 'essere' -o 'conjugation_table.csv' ``` -------------------------------- ### Use MLConjug3 with Pre-trained Models (Python) Source: https://github.com/ars-linguistica/mlconjug3/blob/master/docs/_sources/usage.rst.txt This snippet demonstrates how to use the MLConjug3 library in a Python project with pre-trained conjugation models. It shows initialization with a specified language and how to retrieve conjugated forms of verbs. It also includes an example of iterating through all conjugated forms of a verb. ```python import mlconjug3 # To use mlconjug3 with the default parameters and a pre-trained conjugation model. default_conjugator = mlconjug3.Conjugator(language='fr') # Verify that the model works test1 = default_conjugator.conjugate("manger").conjug_info['Indicatif']['Passé Simple']['1p'] test2 = default_conjugator.conjugate("partir").conjug_info['Indicatif']['Passé Simple']['1p'] test3 = default_conjugator.conjugate("facebooker").conjug_info['Indicatif']['Passé Simple']['1p'] test4 = default_conjugator.conjugate("astigratir").conjug_info['Indicatif']['Passé Simple']['1p'] test5 = default_conjugator.conjugate("mythoner").conjug_info['Indicatif']['Passé Simple']['1p'] print(test1) print(test2) print(test3) print(test4) print(test5) # You can now iterate over all conjugated forms of a verb by using the newly added Verb.iterate() method. default_conjugator = mlconjug3.Conjugator(language='en') test_verb = default_conjugator.conjugate("be") all_conjugated_forms = test_verb.iterate() print(all_conjugated_forms) ``` -------------------------------- ### Access Verb Database with ConjugManager Source: https://context7.com/ars-linguistica/mlconjug3/llms.txt Provides examples for querying the verb database, validating verb endings, and retrieving specific conjugation template information without machine learning. ```python manager = ConjugManager(language='fr') verb_info = manager.get_verb_info('aimer') print(f"Template: {verb_info.template}") ``` -------------------------------- ### Create a New Branch Source: https://github.com/ars-linguistica/mlconjug3/blob/master/CONTRIBUTING.rst Before starting work on a bug fix or new feature, create a new branch to isolate your changes. This command creates and switches to a new branch with the specified name. ```shell git checkout -b name-of-your-bugfix-or-feature ``` -------------------------------- ### Install MLConjug3 via Conda Source: https://github.com/ars-linguistica/mlconjug3/blob/master/docs/installation.html Installs MLConjug3 using the conda package manager, recommended for Apple M1 users to ensure pre-compiled dependencies. ```bash conda config --add channels conda-forge conda config --set channel_priority strict conda install mlconjug3 ``` -------------------------------- ### Prepare Dataset for Conjugation Models Source: https://context7.com/ars-linguistica/mlconjug3/llms.txt Demonstrates how to initialize a dataset from the conjugator's verb manager and split the data into training and testing sets based on specified thresholds and proportions. ```python dataset = DataSet(conjugator.conjug_manager.verbs) dataset.split_data(threshold=8, proportion=0.7) print(f"Training samples: {len(dataset.train_input)}") ``` -------------------------------- ### Install mlconjug3 using Conda Source: https://github.com/ars-linguistica/mlconjug3/blob/master/HISTORY.rst This command installs the mlconjug3 package from the conda-forge channel. It is particularly useful for users with MacBooks featuring Apple M1 processors, ensuring maximum compatibility. ```console conda install -c conda-forge mlconjug3 ``` -------------------------------- ### Command-line Conjugation with MLConjug3 Source: https://github.com/ars-linguistica/mlconjug3/blob/master/docs/usage.html Demonstrates how to use MLConjug3 from the command line to conjugate verbs. It shows basic conjugation, specifying language, and outputting to a file. ```bash $ mlconjug3 manger $ mlconjug3 bring -l en $ mlconjug3 gallofar --language es $ mlconjug3 -o, --output (Path of the filename for storing the conjugation tables.) $ mlconjug3 -s, --subject (The subject format type for the conjugated forms). The values can be 'abbrev' or 'pronoun'. The default value is 'abbrev'. $ mlconjug3 -h Show the help menu ``` -------------------------------- ### Get Verb Info Source: https://github.com/ars-linguistica/mlconjug3/blob/master/docs/_modules/mlconjug3/PyVerbiste.html Retrieves information about a specific verb. ```APIDOC ## Get Verb Info ### Description Retrieves detailed information about a specific verb, including its infinitive, root, and conjugation template. Returns None if the verb is not found. ### Method Public Method ### Endpoint N/A (Method Call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python conjugator = ConjugManager(language='fr') verb_info = conjugator.get_verb_info('manger') if verb_info: print(f"Root: {verb_info.root}, Template: {verb_info.template}") ``` ### Response #### Success Response (200) - **VerbInfo object or None**: An object containing verb details (infinitive, root, template) or None if the verb is not found. #### Response Example ```json { "example": "{\"infinitive\": \"manger\", \"root\": \"mang\", \"template\": \"er\"}" } ``` ``` -------------------------------- ### Dataset Creation and Splitting Source: https://context7.com/ars-linguistica/mlconjug3/llms.txt Demonstrates how to create a dataset from a conjugator's verb dictionary and split it into training and testing sets. ```APIDOC ## Dataset Creation and Splitting ### Description This section shows how to create a `DataSet` object from a conjugator's verb dictionary and then split this data into training and testing subsets. It also demonstrates accessing properties of the created dataset like the total number of verbs, templates, and verb counts per template. ### Method N/A (Code Example) ### Endpoint N/A (Code Example) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```python from mlconjug3 import Conjugator, DataSet # Initialize conjugator for a language (e.g., French) language = 'fr' conjugator = Conjugator(language=language) # Create dataset from conjugator's verb dictionary dataset = DataSet(conjugator.conjug_manager.verbs) print(f"Total verbs: {len(list(dataset.verbs))}") print(f"Total templates: {len(dataset.templates)}") print(f"First 5 templates: {dataset.templates[:5]}") # Split data into training and testing sets # threshold: minimum verbs per class to split (default 8) # proportion: training set proportion (default 0.5) dataset.split_data(threshold=8, proportion=0.7) print(f"\nTraining samples: {len(dataset.train_input)}") print(f"Training labels: {len(dataset.train_labels)}") print(f"Test samples: {len(dataset.test_input)}") print(f"Test labels: {len(dataset.test_labels)}") # Access conjugation dictionary grouped by template print(f"\nTemplates with verb counts:") for template, verbs in list(dataset.dict_conjug.items())[:3]: print(f" {template}: {len(verbs)} verbs") ``` ### Response #### Success Response (200) N/A (This is a code example, not an API response) #### Response Example ``` Total verbs: 1000 Total templates: 50 First 5 templates: ['aim:er', 'fin:ir', 'vendre', 'attendre', 'prendre'] Training samples: 800 Training labels: 800 Test samples: 200 Test labels: 200 Templates with verb counts: aim:er: 100 verbs fin:ir: 80 verbs vendre: 60 verbs ``` ``` -------------------------------- ### Get Conjugation Info Source: https://github.com/ars-linguistica/mlconjug3/blob/master/docs/_modules/mlconjug3/PyVerbiste.html Retrieves conjugation patterns for a given template. ```APIDOC ## Get Conjugation Info ### Description Retrieves the conjugation patterns (suffixes) associated with a given verb template. Returns None if the template is not found. ### Method Public Method ### Endpoint N/A (Method Call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python conjugator = ConjugManager(language='fr') conjugation_patterns = conjugator.get_conjug_info('er') if conjugation_patterns: print(conjugation_patterns) ``` ### Response #### Success Response (200) - **OrderedDict or None**: An OrderedDict containing the conjugated suffixes for the template, or None if the template is not found. #### Response Example ```json { "example": "{\"indicatif\": {\"présent\": {\"1sg\": \"e\", \"2sg\": \"es\", \"3sg\": \"e\", \"1pl\": \"ons\", \"2pl\": \"ez\", \"3pl\": \"ent\"}}}" } ``` ``` -------------------------------- ### GET /iterate Source: https://github.com/ars-linguistica/mlconjug3/blob/master/docs/modules.html Retrieves a list of all conjugated forms for the current verb object. ```APIDOC ## GET /iterate ### Description Iterates over all conjugated forms and returns a list of tuples representing those forms. ### Method GET ### Endpoint /iterate ### Response #### Success Response (200) - **forms** (list) - A list of tuples containing the conjugated forms. #### Response Example [ ["1s", "amo"], ["2s", "ami"] ] ``` -------------------------------- ### Configure Machine Learning Models Source: https://context7.com/ars-linguistica/mlconjug3/llms.txt Demonstrates how to initialize the Model class with default settings or customize the scikit-learn pipeline components for verb conjugation prediction. ```python import mlconjug3 from mlconjug3 import Model from sklearn.ensemble import RandomForestClassifier from sklearn.feature_extraction.text import CountVectorizer from sklearn.feature_selection import SelectFromModel from sklearn.svm import LinearSVC from functools import partial from mlconjug3.feature_extractor import extract_verb_features # Create a model with default components model = Model(language='fr') # Create model with custom classifier custom_vectorizer = CountVectorizer( analyzer=partial(extract_verb_features, lang='fr', ngram_range=(2, 7)), binary=True, lowercase=False ) custom_selector = SelectFromModel( LinearSVC(penalty='l1', max_iter=12000, dual=False) ) custom_classifier = RandomForestClassifier(n_estimators=100, random_state=42) custom_model = Model( vectorizer=custom_vectorizer, feature_selector=custom_selector, classifier=custom_classifier, language='fr' ) ``` -------------------------------- ### Configure CLI Settings Source: https://context7.com/ars-linguistica/mlconjug3/llms.txt Shows how to define persistent settings such as default language, output format, and terminal theme styling using TOML or YAML configuration files. ```toml language = "fr" subject = "pronoun" output = "conjugations.json" file_format = "json" [theme] header_style = "bold #0D47A1" mood_style = "bold #F9A825" tense_style = "bold bright_magenta" person_style = "bold cyan" conjugation_style = "bold #4CAF50" ``` ```yaml language: "es" subject: "pronoun" output: "spanish_verbs.json" file_format: "json" theme: header_style: "bold blue" mood_style: "bold yellow" tense_style: "bold magenta" person_style: "bold cyan" conjugation_style: "bold green" ``` -------------------------------- ### Initialize Verb Object Source: https://github.com/ars-linguistica/mlconjug3/blob/master/docs/modules.html Demonstrates how to instantiate a Verb object with verb information and conjugation details. The subject parameter controls pronoun formatting. ```python from mlconjug3.PyVerbiste import Verb # Example instantiation verb_obj = Verb(verb_info=info, conjug_info=conjug_data, subject='abbrev', predicted=False) ``` -------------------------------- ### POST /model/initialize Source: https://github.com/ars-linguistica/mlconjug3/blob/master/docs/_modules/mlconjug3/mlconjug.html Initializes a scikit-learn pipeline for verb conjugation prediction with default or custom components. ```APIDOC ## POST /model/initialize ### Description Initializes the machine learning pipeline including vectorizer, feature selector, and classifier. If parameters are omitted, default high-accuracy components are used. ### Method POST ### Endpoint /model/initialize ### Parameters #### Request Body - **vectorizer** (object) - Optional - scikit-learn Vectorizer. - **feature_selector** (object) - Optional - scikit-learn feature selector. - **classifier** (object) - Optional - scikit-learn classifier. - **language** (string) - Optional - Language of the verb corpus. ### Request Example { "language": "fr" } ### Response #### Success Response (200) - **pipeline** (object) - The initialized scikit-learn pipeline object. #### Response Example { "status": "initialized", "language": "fr" } ``` -------------------------------- ### Get Conjugation Information Source: https://github.com/ars-linguistica/mlconjug3/blob/master/docs/_modules/mlconjug3/PyVerbiste.html Retrieves the conjugation suffixes for a given template. It returns a deep copy of the OrderedDict containing the conjugation patterns if the template is found, otherwise returns None. ```python def get_conjug_info(self, template): """ Gets conjugation information corresponding to the given template. :param template: string. Name of the verb ending pattern. :return: OrderedDict or None. OrderedDict containing the conjugated suffixes of the template. """ if template not in self.conjugations.keys(): return None return copy.deepcopy(self.conjugations[template]) ``` -------------------------------- ### Conjugate a verb using Conjugator Source: https://github.com/ars-linguistica/mlconjug3/blob/master/docs/usage.rst Demonstrates how to initialize the Conjugator class and perform a basic conjugation of a verb. The result provides access to all conjugated forms. ```python from mlconjug3 import Conjugator # initialize the conjugator conjugator = Conjugator() # conjugate the verb "parler" verb = conjugator.conjugate("parler") # print all the conjugated forms as a list of tuples. print(verb.iterate()) ``` -------------------------------- ### Conjugate Verbs via CLI Source: https://context7.com/ars-linguistica/mlconjug3/llms.txt Demonstrates how to use the mlconjug3 command-line interface to conjugate verbs across different languages, specify pronoun formats, and export results to JSON or CSV files. ```bash mlconjug3 manger mlconjug3 -l en -s abbrev bring mlconjug3 -l fr -s pronoun aimer être aller mlconjug3 -l es -s pronoun hablar -o conjugation_table.json -f json mlconjug3 -l it -s abbrev parlare avere essere -o conjugations.csv -f csv mlconjug3 -c /path/to/config.toml manger mlconjug3 -c /path/to/config.toml -l en -s pronoun -o output.json bring ``` -------------------------------- ### Get Verb Information Source: https://github.com/ars-linguistica/mlconjug3/blob/master/docs/_modules/mlconjug3/PyVerbiste.html Retrieves information about a verb, including its infinitive, root, and conjugation template. It returns a VerbInfo object if the verb exists in the loaded data, otherwise returns None. ```python def get_verb_info(self, verb): """ Gets verb information and returns a VerbInfo instance. :param verb: string. Verb to conjugate. :return: VerbInfo object or None. """ if verb not in self.verbs.keys(): return None infinitive = verb root = self.verbs[verb]['root'] template = self.verbs[verb]['template'] return VerbInfo(infinitive, root, template) ``` -------------------------------- ### Conjugate Verbs with mlconjug3 Source: https://context7.com/ars-linguistica/mlconjug3/llms.txt Demonstrates initializing the Conjugator class for different languages and retrieving specific conjugation forms for known verbs. ```python import mlconjug3 # Initialize conjugator for French (default language) conjugator_fr = mlconjug3.Conjugator(language='fr') # Conjugate a single French verb verb = conjugator_fr.conjugate('manger') print(f"Verb: {verb.name}") print(f"Template: {verb.verb_info.template}") print(f"Root: {verb.verb_info.root}") # Access specific conjugation forms indicatif_present = verb['Indicatif']['Présent'] print("Present tense conjugation:") for person, form in indicatif_present.items(): print(f" {person}: {form}") # Initialize conjugator for English conjugator_en = mlconjug3.Conjugator(language='en') verb_en = conjugator_en.conjugate('bring') print(f"\nEnglish verb: {verb_en.name}") print(f"Past tense: {verb_en['indicative']['indicative past tense']}") # Initialize conjugator for Spanish conjugator_es = mlconjug3.Conjugator(language='es') verb_es = conjugator_es.conjugate('hablar') print(f"\nSpanish verb: {verb_es.name}") ``` -------------------------------- ### Initialize DataSet for ML Tasks Source: https://github.com/ars-linguistica/mlconjug3/blob/master/docs/_modules/mlconjug3/mlconjug.html Initializes the DataSet object for machine learning tasks, processing a dictionary of verbs and their conjugation classes. It prepares lists for verbs, templates, and sets up variables for data splitting. ```python def __init__(self, verbs_dict): self.verbs_dict = verbs_dict self.verbs = self.verbs_dict.keys() self.templates = sorted( {verb['template'] for verb in self.verbs_dict.values()} ) self.verbs_list = [] self.templates_list = [] self.dict_conjug = None self.min_threshold = 8 self.split_proportion = 0.5 self.train_input = [] self.train_labels = [] self.test_input = [] self.test_labels = [] self.construct_dict_conjug() return ``` -------------------------------- ### Initialize Conjugator with a custom model Source: https://github.com/ars-linguistica/mlconjug3/blob/master/docs/usage.rst Explains how to load a pre-trained model using joblib and pass it to the Conjugator class for custom conjugation tasks. ```python import joblib from mlconjug3 import Conjugator # load the trained model from file my_french_model = joblib.load("my_french_model.pickle") # create an instance of the Conjugator class with the custom model conjugator = Conjugator(language='fr', model=my_french_model) # conjugate a verb conjugations = conjugator.conjugate("aimer") ``` -------------------------------- ### Clone mlconjug3 Repository Source: https://github.com/ars-linguistica/mlconjug3/blob/master/CONTRIBUTING.rst This command clones the mlconjug3 project repository from GitHub to your local machine. It is the first step in setting up your development environment. ```shell git clone git@github.com:Ars-Linguistica/mlconjug3.git ``` -------------------------------- ### Train a New MLConjug3 Model (Python) Source: https://github.com/ars-linguistica/mlconjug3/blob/master/docs/_sources/usage.rst.txt This Python code demonstrates how to train a new MLConjug3 conjugation model. It involves setting up a language, defining vectorizer and feature reduction parameters, initializing a dataset, training the model, and then using the trained model to conjugate verbs. The trained model can also be saved. ```python import mlconjug3 from functools import partial import pickle # Set a language to train the Conjugator on lang = 'fr' # Set a ngram range sliding window for the vectorizer ngrange = (2,7) # Transforms dataset with CountVectorizer. We pass the function extract_verb_features to the CountVectorizer. vectorizer = mlconjug3.CountVectorizer(analyzer=partial(mlconjug3.extract_verb_features, lang=lang, ngram_range=ngrange), binary=True) # Feature reduction feature_reductor = mlconjug3.SelectFromModel(mlconjug3.LinearSVC(penalty="l1", max_iter=12000, dual=False, verbose=0)) # Prediction Classifier classifier = mlconjug3.SGDClassifier(loss="log", penalty='elasticnet', l1_ratio=0.15, max_iter=4000, alpha=1e-5, random_state=42, verbose=0) # Initialize Data Set dataset = mlconjug3.DataSet(mlconjug3.Verbiste(language=lang).verbs) dataset.construct_dict_conjug() dataset.split_data(proportion=0.9) # Initialize Conjugator model = mlconjug3.Model(vectorizer, feature_reductor, classifier) conjugator = mlconjug3.Conjugator(lang, model) #Training and prediction conjugator.model.train(dataset.train_input, dataset.train_labels) predicted = conjugator.model.predict(dataset.test_input) # Assess the performance of the model's predictions score = len([a == b for a, b in zip(predicted, dataset.test_labels) if a == b]) / len(predicted) print('The score of the model is {0}'.format(score)) # Verify that the model works test1 = conjugator.conjugate("manger").conjug_info['Indicatif']['Passé Simple']['1p'] test2 = conjugator.conjugate("partir").conjug_info['Indicatif']['Passé Simple']['1p'] test3 = conjugator.conjugate("facebooker").conjug_info['Indicatif']['Passé Simple']['1p'] test4 = conjugator.conjugate("astigratir").conjug_info['Indicatif']['Passé Simple']['1p'] test5 = conjugator.conjugate("mythoner").conjug_info['Indicatif']['Passé Simple']['1p'] print(test1) print(test2) print(test3) print(test4) print(test5) # Save trained model with open('path/to/save/data/trained_model-fr.pickle', 'wb') as file: pickle.dump(conjugator.model, file) ``` -------------------------------- ### Run Project Tests Source: https://github.com/ars-linguistica/mlconjug3/blob/master/CONTRIBUTING.rst This command executes the project's test suite using pytest, ensuring that your changes are compatible with the project's requirements. It's recommended to run tests before committing. ```shell poetry run pytest ``` -------------------------------- ### ConjugatorTrainer - Complete Training Workflow Source: https://context7.com/ars-linguistica/mlconjug3/llms.txt Utilizes the `ConjugatorTrainer` class for a comprehensive workflow including training, evaluation, and saving of conjugation models. ```APIDOC ## ConjugatorTrainer - Complete Training Workflow ### Description The `ConjugatorTrainer` class streamlines the entire process of training, evaluating, and saving conjugation models. This example demonstrates setting up training parameters, initializing the necessary components, creating a `ConjugatorTrainer` instance, and then executing the training, evaluation, and saving steps. It also shows how to make predictions using the trainer. ### Method N/A (Code Example) ### Endpoint N/A (Code Example) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```python from mlconjug3 import Conjugator, Model, DataSet from mlconjug3.utils import ConjugatorTrainer # Setup training parameters language = 'es' output_folder = './models' split_proportion = 0.8 # Initialize components conjugator = Conjugator(language=language) dataset = DataSet(conjugator.conjug_manager.verbs) model = Model(language=language) # Create trainer trainer = ConjugatorTrainer( lang=language, output_folder=output_folder, split_proportion=split_proportion, dataset=dataset, model=model ) # Train the model trainer.train() # Evaluate model performance trainer.evaluate() # Output: The score of the es model is 0.95 with 234 misses out of 4680 entries. # Save the trained model trainer.save() # Saves to: ./models/trained_model-es.pickle # Make predictions predictions = trainer.predict() print(f"Made {len(predictions)} predictions") ``` ### Response #### Success Response (200) N/A (This is a code example, not an API response) #### Response Example ``` The score of the es model is 0.95 with 234 misses out of 4680 entries. Made 4680 predictions ``` ``` -------------------------------- ### Conjugate Multiple Verbs via Multiprocessing Source: https://context7.com/ars-linguistica/mlconjug3/llms.txt Shows how to pass a list of verbs to the conjugate method to leverage multiprocessing for efficient batch processing. ```python import mlconjug3 conjugator = mlconjug3.Conjugator(language='fr') # Conjugate multiple verbs at once using multiprocessing verbs_to_conjugate = ['aimer', 'finir', 'vendre', 'aller', 'avoir', 'être'] results = conjugator.conjugate(verbs_to_conjugate) for verb_obj in results: if verb_obj: print(f"\n{verb_obj.name.upper()} ({verb_obj.verb_info.template})") if 'Subjonctif' in verb_obj.conjug_info: subj_present = verb_obj.conjug_info['Subjonctif'].get('Présent', {}) print(" Subjunctive present:") for person, form in subj_present.items(): print(f" {person}: {form}") ``` -------------------------------- ### Automate Training Workflow with ConjugatorTrainer Source: https://context7.com/ars-linguistica/mlconjug3/llms.txt Utilizes the ConjugatorTrainer class to streamline the training, evaluation, and serialization of conjugation models into pickle files. ```python trainer = ConjugatorTrainer(lang='es', output_folder='./models', dataset=dataset, model=model) trainer.train() trainer.evaluate() trainer.save() ``` -------------------------------- ### Configure Conjugation Output Subjects Source: https://context7.com/ars-linguistica/mlconjug3/llms.txt Demonstrates how to toggle between abbreviated person markers and full personal pronouns in conjugation results using the subject parameter. ```python import mlconjug3 conjugator = mlconjug3.Conjugator(language='fr') # Conjugate with abbreviated subjects (default) verb_abbrev = conjugator.conjugate('parler', subject='abbrev') print("With abbreviations:") for person, form in verb_abbrev['Indicatif']['Présent'].items(): print(f" {person}: {form}") # Conjugate with full pronouns verb_pronoun = conjugator.conjugate('parler', subject='pronoun') print("\nWith full pronouns:") for person, form in verb_pronoun['Indicatif']['Présent'].items(): print(f" {person}: {form}") ``` -------------------------------- ### Predict Conjugation for Unknown Verbs Source: https://context7.com/ars-linguistica/mlconjug3/llms.txt Illustrates using the machine learning pipeline to predict conjugation patterns for non-existent or made-up verbs, including confidence scores. ```python import mlconjug3 conjugator = mlconjug3.Conjugator(language='fr') # Conjugate a made-up verb (not in Verbiste database) invented_verb = conjugator.conjugate('googleiser') if invented_verb: print(f"Verb: {invented_verb.name}") print(f"Predicted: {invented_verb.predicted}") print(f"Confidence score: {invented_verb.confidence_score}") print(f"Predicted template: {invented_verb.verb_info.template}") # Access conjugated forms print("\nIndicatif Présent:") for person, form in invented_verb['Indicatif']['Présent'].items(): print(f" {person}: {form}") # English example conjugator_en = mlconjug3.Conjugator(language='en') made_up_en = conjugator_en.conjugate('yeetify') print(f"\nEnglish made-up verb: {made_up_en.name}") print(f"Confidence: {made_up_en.confidence_score}") ``` -------------------------------- ### Initialize Scikit-learn Model Pipeline Source: https://github.com/ars-linguistica/mlconjug3/blob/master/docs/_modules/mlconjug3/mlconjug.html Initializes a scikit-learn pipeline for machine learning tasks, including a vectorizer, feature selector, and classifier. It provides default components if none are supplied, aiming for high prediction accuracy. ```python def __init__(self, vectorizer=None, feature_selector=None, classifier=None, language=None): if not vectorizer: vectorizer = CountVectorizer(analyzer=partial(extract_verb_features, lang=language, ngram_range=(2, 7)), binary=True) if not feature_selector: feature_selector = SelectFromModel(LinearSVC(penalty='l1', max_iter=12000, dual=False, verbose=2)) if not classifier: classifier = SGDClassifier(loss='log', penalty='elasticnet', l1_ratio=0.15, max_iter=4000, alpha=1e-5, random_state=42, verbose=2) self.pipeline = Pipeline([('vectorizer', vectorizer), ('feature_selector', feature_selector), ('classifier', classifier)]) self.language = language return ``` -------------------------------- ### Construct Conjugation Dictionary Source: https://github.com/ars-linguistica/mlconjug3/blob/master/docs/_modules/mlconjug3/mlconjug.html Populates the dictionary containing conjugation templates and lists of verbs and their corresponding templates. It shuffles verb items and assigns them to templates based on the provided dictionary. ```python def construct_dict_conjug(self): """ | Populates the dictionary containing the conjugation templates. | Populates the lists containing the verbs and their templates. """ conjug = defaultdict(list) verb_items = list(self.verbs_dict.items()) Random(42).shuffle(verb_items) for verb, info_verb in verb_items: self.verbs_list.append(verb) self.templates_list.append(self.templates.index(info_verb["template"])) conjug[info_verb["template"]].append(verb) self.dict_conjug = conjug return ``` -------------------------------- ### Load Conjugation Data - Romanian Verb Source: https://github.com/ars-linguistica/mlconjug3/blob/master/docs/_modules/mlconjug3/PyVerbiste.html The `_load_conjug` method in `VerbRo` populates inflected verb forms for Romanian. It manages personal pronouns, negation, and specific imperative conjugations, applying language-specific prefixes for infinitive forms and handling different pronoun mappings based on tense and mood. ```python def _load_conjug(self): """ | Populates the inflected forms of the verb. | Adds personal pronouns to the inflected verbs. """ for mood, tense in self.conjug_info.items(): for tense_name, persons in tense.items(): if isinstance(persons, list): persons_dict = OrderedDict() for pers, term in persons: if len(persons) == 6: key = _PRONOUNS[self.language][self.subject][pers] elif tense_name.startswith('Imperativ Imperativ'): key = _IMPERATIVE_PRONOUNS[self.language][self.subject][pers] elif tense_name == 'Imperativ Negativ': key = _NEGATION[self.language] else: key = pers if term is not None and term != '-': if tense_name == 'Imperativ Negativ': persons_dict[key] = ' '.join((_NEGATION[self.language], self.verb_info.root + term)) else: self.conjugate_person(key, persons_dict, term) else: persons_dict[key] = None self.conjug_info[mood][tense_name] = persons_dict elif isinstance(persons, str): prefix = 'a ' if tense_name == 'Infinitiv Afirmativ' else '' self.conjug_info[mood][tense_name] = prefix + self.verb_info.root + persons return ``` -------------------------------- ### Train a Custom French Conjugator Model in Python Source: https://github.com/ars-linguistica/mlconjug3/blob/master/docs/usage.rst This script demonstrates how to initialize and train a custom conjugation model using the ConjugatorTrainer class. It configures the vectorizer, feature selector, and classifier before executing the training, prediction, and evaluation pipeline. ```python """ Script to train a new french Conjugator model """ import mlconjug3 from mlconjug3.feature_extractor import extract_verb_features from functools import partial lang = "fr" params = {'lang': lang, 'output_folder': "models", 'split_proportion': 0.8, 'dataset': mlconjug3.DataSet(mlconjug3.Verbiste(lang).verbs), 'model': mlconjug3.Model( language=lang, vectorizer=mlconjug3.CountVectorizer(analyzer=partial(extract_verb_features, lang=lang, ngram_range=(2, 7)), binary=True, lowercase=False), feature_selector=mlconjug3.SelectFromModel(mlconjug3.LinearSVC(penalty = "l1", max_iter = 12000, dual = False, verbose = 0)), classifier=mlconjug3.SGDClassifier(loss = "log", penalty = "elasticnet", l1_ratio = 0.15, max_iter = 40000, alpha = 1e-5, verbose = 0) ) } ct = mlconjug3.utils.ConjugatorTrainer(**params) print("training model...") ct.train() print("model has benn trained.") ct.predict() print("evaluating model") ct.evaluate() print("saving model") ct.save() ``` -------------------------------- ### Initialize Language-Specific Conjugators Source: https://context7.com/ars-linguistica/mlconjug3/llms.txt Demonstrates the use of the mlconjug3 Python API to instantiate language-specific verb conjugators, which handle unique grammatical rules such as gender, imperatives, and prefixes. ```python import mlconjug3 conjugator_fr = mlconjug3.Conjugator(language='fr') verb_fr = conjugator_fr.conjugate('manger', subject='pronoun') conjugator_es = mlconjug3.Conjugator(language='es') verb_es = conjugator_es.conjugate('hablar', subject='pronoun') conjugator_it = mlconjug3.Conjugator(language='it') verb_it = conjugator_it.conjugate('parlare', subject='pronoun') conjugator_pt = mlconjug3.Conjugator(language='pt') verb_pt = conjugator_pt.conjugate('falar', subject='pronoun') conjugator_ro = mlconjug3.Conjugator(language='ro') verb_ro = conjugator_ro.conjugate('vorbi', subject='pronoun') conjugator_en = mlconjug3.Conjugator(language='en') verb_en = conjugator_en.conjugate('code', subject='pronoun') ``` -------------------------------- ### Initialize Verb Object Source: https://github.com/ars-linguistica/mlconjug3/blob/master/docs/_modules/mlconjug3/PyVerbiste.html Constructor for the Verb class, initializing verb information, conjugation data, and subject settings. It triggers the internal loading of conjugation forms upon instantiation. ```python def __init__(self, verb_info, conjug_info, subject='abbrev', predicted=False): self.name = verb_info.infinitive self.verb_info = verb_info self.conjug_info = conjug_info self.subject = subject self.predicted = predicted self.confidence_score = None self._load_conjug() return ``` -------------------------------- ### ConjugManager Initialization Source: https://github.com/ars-linguistica/mlconjug3/blob/master/docs/_modules/mlconjug3/PyVerbiste.html Initializes the ConjugManager with a specified language, loading verbs and conjugation data. ```APIDOC ## ConjugManager Initialization ### Description Initializes the ConjugManager with a specified language, loading verbs and conjugation data from resource files. It validates the provided language against supported languages. ### Method Constructor ### Endpoint N/A (Class Initialization) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python conjugator = ConjugManager(language='fr') ``` ### Response #### Success Response (200) N/A (Initialization) #### Response Example N/A ``` -------------------------------- ### Initialize ConjugManager Source: https://github.com/ars-linguistica/mlconjug3/blob/master/docs/_modules/mlconjug3/PyVerbiste.html Initializes the ConjugManager with a specified language, loading verbs and conjugations from resource files. It validates the language input and sets up internal data structures for conjugation lookups. Dependencies include pkg_resources for file access and json for parsing. ```python def __init__(self, language='fr'): if language not in _LANGUAGES: raise ValueError(_('Unsupported language.\nThe allowed languages are fr, en, es, it, pt, ro.')) self.language = 'fr' if language == 'default' else language self.verbs = {} self.conjugations = OrderedDict() verbs_file = pkg_resources.resource_filename(_RESOURCE_PACKAGE, _VERBS_RESOURCE_PATH[self.language]) self._load_verbs(verbs_file) self._allowed_endings = self._detect_allowed_endings() conjugations_file = pkg_resources.resource_filename(_RESOURCE_PACKAGE, _CONJUGATIONS_RESOURCE_PATH[self.language]) self._load_conjugations(conjugations_file) self.templates = sorted(self.conjugations.keys()) return ``` -------------------------------- ### Run tests and quality checks for mlconjug3 Source: https://github.com/ars-linguistica/mlconjug3/blob/master/docs/contributing.html Commands to verify code quality using flake8 and execute test suites using pytest or tox. ```bash flake8 mlconjug3 tests python setup.py test py.test tox ``` -------------------------------- ### Run Project Tests with Tox Source: https://github.com/ars-linguistica/mlconjug3/blob/master/CONTRIBUTING.rst This command uses tox to run tests across different Python environments, ensuring compatibility with supported Python versions (3.8 to 3.11). It's a comprehensive way to validate your changes. ```shell poetry run tox ```