Socket
Book a DemoInstallSign in
Socket

nlp-synt-data

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nlp-synt-data

Synthesized Data for NLP Tasks

pipPyPI
Version
0.0.11
Maintainers
1

nlp-synt-data PyPi version t

Synthetic Data Tools for Natural Language Processing (NLP) and Large Language Models (LLM) tasks

  • generate prompts (and prompt ids)
  • generate synthetic data (and data ids)
  • retrieve prompts and data from ids (to reduce generated dataset size)

Installation

pip install nlp-synt-data

Quickstart

An example of this library with ollama

from nlp_synt_data import *
import ollama

# generate prompts
prompts_dict = {
    "a": ["promptA0", "promptA1"],
    "b": ["promptB0", "promptB1"],
    "c": ["promptC0", "promptC1"],
    "d": ["promptD0", "promptD1"],
    "e": ["promptE0", "promptE1"],
}
prompts = PromptGenerator.generate(prompts_dict, [["c","e"],["a","b","d"]])

# generate texts
texts_with_keys = [
    ("[PERSON]","label0"),
    ("[PERSON] is working as a [JOB] in [POS]","label1"),
    ]
substitutions = {
    "JOB": [("job0","labeljob0"), ("job1","labeljob1")],
    "PERSON": [("person0","labelperson0"), ("person1","labelperson1")],
    "POS": [("pos0","labelpos0"), ("pos1","labelpos1")]
}
texts = DataGenerator.generate(texts_with_keys, substitutions)

# generate responses
model_func = lambda prompt, text: ollama.chat(model='llama3:instruct', messages=[
                { 'role': 'system', 'content': prompt, },
                { 'role': 'user', 'content': text, },
            ])['message']['content']
ResponseGenerator.generate("results.csv", texts, prompts, model_func)

results.csv

prompt_idtext_idtext_labelsresponsetext_PERSON_valuetext_JOB_valuetext_POS_valuetext_PERSON_labeltext_JOB_labeltext_POS_label
c#0_e#0t#0_PERSON#0label0responseperson0labelperson0
c#0_e#0t#0_PERSON#1label0responseperson1labelperson1
c#0_e#0t#1_JOB#0_PERSON#0_POS#0label1responseperson0job0pos0labelperson0labeljob0labelpos0
c#0_e#0t#1_JOB#0_PERSON#0_POS#1label1responseperson0job0pos1labelperson0labeljob0labelpos1
c#0_e#0t#1_JOB#0_PERSON#1_POS#0label1responseperson1job0pos0labelperson1labeljob0labelpos0
..............................

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts