Skip to main content

Synthesized Data for NLP Tasks

Project description

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_id text_id text_labels response
c#0_e#0 t#0_PERSON#0 ['label0', 'labelperson0'] response
c#0_e#0 t#0_PERSON#1 ['label0', 'labelperson1'] response
c#0_e#0 t#1_JOB#0_PERSON#0_POS#0 ['label1', 'labeljob0', 'labelperson0', 'labelpos0'] response
c#0_e#0 t#1_JOB#0_PERSON#0_POS#1 ['label1', 'labeljob0', 'labelperson0', 'labelpos1'] response
c#0_e#0 t#1_JOB#0_PERSON#1_POS#0 ['label1', 'labeljob0', 'labelperson1', 'labelpos0'] response
c#0_e#0 t#1_JOB#0_PERSON#1_POS#1 ['label1', 'labeljob0', 'labelperson1', 'labelpos1'] response
c#0_e#0 t#1_JOB#1_PERSON#0_POS#0 ['label1', 'labeljob1', 'labelperson0', 'labelpos0'] response
c#0_e#0 t#1_JOB#1_PERSON#0_POS#1 ['label1', 'labeljob1', 'labelperson0', 'labelpos1'] response
c#0_e#0 t#1_JOB#1_PERSON#1_POS#0 ['label1', 'labeljob1', 'labelperson1', 'labelpos0'] response
c#0_e#0 t#1_JOB#1_PERSON#1_POS#1 ['label1', 'labeljob1', 'labelperson1', 'labelpos1'] response
... ... ... ...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nlp_synt_data-0.0.6.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nlp_synt_data-0.0.6-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file nlp_synt_data-0.0.6.tar.gz.

File metadata

  • Download URL: nlp_synt_data-0.0.6.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for nlp_synt_data-0.0.6.tar.gz
Algorithm Hash digest
SHA256 88346a3355472b698e8778ff13888ee93353ad2a16936dd0874c947c9ec730e7
MD5 7bccfbba831594ea55b709c551463451
BLAKE2b-256 89eee14f31620fa882830542713d70da91bbd05dbac56e6f84904e7c7188ec24

See more details on using hashes here.

File details

Details for the file nlp_synt_data-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: nlp_synt_data-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for nlp_synt_data-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 ffba04e4700d81fe0e0595f38dac6e2981eb84d9c9995bef5a4910e1c8e33055
MD5 ed6150dc7cbec87b8a3fd53dd1239a4b
BLAKE2b-256 ff4914016f372347f312720726c735973b015f8f9b61a9af462d558a0a3641fa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page