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 synthesized data (and data ids)
  • retrieve prompts and data from ids (to reduce generated dataset size)

Installation

pip install nlp-synt-data

PromptGenerator

generate

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

get

PromptGenerator.get("c#0_e#0", prompts_dict)
promptC0 promptE0

DataGenerator

generate

texts_with_keys = [
    "[PERSON]",
    "[PERSON] is working as a [JOB] in [POS]",
    ]
substitutions = {
    "JOB": ["job0", "job1"],
    "PERSON": ["person0", "person1"],
    "POS": ["pos0", "pos1"]
}

DataGenerator.generate(texts_with_keys, substitutions)
[('t#0_PERSON#0', 'person0'), ('t#0_PERSON#1', 'person1'), ('t#1_JOB#0_PERSON#0_POS#0', 'person0 is working as a job0 in pos0'), ('t#1_JOB#0_PERSON#0_POS#1', 'person0 is working as a job0 in pos1'), ('t#1_JOB#0_PERSON#1_POS#0', 'person1 is working as a job0 in pos0'), ('t#1_JOB#0_PERSON#1_POS#1', 'person1 is working as a job0 in pos1'), ('t#1_JOB#1_PERSON#0_POS#0', 'person0 is working as a job1 in pos0'), ('t#1_JOB#1_PERSON#0_POS#1', 'person0 is working as a job1 in pos1'), ('t#1_JOB#1_PERSON#1_POS#0', 'person1 is working as a job1 in pos0'), ('t#1_JOB#1_PERSON#1_POS#1', 'person1 is working as a job1 in pos1')]

get

DataGenerator.get("t#1_JOB#0_PERSON#0_POS#0", texts_with_keys, substitutions)
{'keys': {'JOB': 'job0', 'PERSON': 'person0', 'POS': 'pos0'}, 'text': 'person0 is working as a job0 in pos0', 'text_with_keys': '[PERSON] is working as a [JOB] in [POS]'}

ResponseGenerator

generate

This is an example of using this library with ollama llm models

prompts = PromptGenerator.generate(prompts_dict, prompt_keys)
data = DataGenerator.generate(texts_with_keys, substitutions)
model_func = lambda prompt, text: ollama.chat(model='llama3:instruct', messages=[
                { 'role': 'system', 'content': prompt, },
                { 'role': 'user', 'content': text, },
            ])['message']['content']
generator.ResponseGenerator.generate("results.csv", data, prompts, model_func)

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.5.tar.gz (4.9 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.5-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nlp_synt_data-0.0.5.tar.gz
  • Upload date:
  • Size: 4.9 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.5.tar.gz
Algorithm Hash digest
SHA256 ec8ebde3f34000df9cad181475a31b4af3cdcfb166edd8b9a409ada7eb8cf839
MD5 73a6de8394dbf42878632eaff183add9
BLAKE2b-256 5635cdb8dfae810033c2df5a85e5994f14ac51030ba519bf184b0dcd0eaef92e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nlp_synt_data-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 5.4 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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 2653f49fe14f75ec0c62121413e25d40cb869304797b52c8c03aeb6ae297a375
MD5 891caf1a28b5ddd640f90bf36366e8c7
BLAKE2b-256 18b0ac45b69ed5ad0e59c4e981ad42f807964eb4d048dd6f77b0e3b8f552ca96

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