tailwiz
tailwiz is an AI-powered tool for analyzing text. It has three main capabilties: classifying text (tailwiz.classify), parsing text given context and prompts (tailwiz.parse), and generating text given prompts (tailwiz.generate).
Quickstart
Install tailwiz by entering into command line:
python -m pip install --upgrade tailwiz
Then run the following in a Python environment for a quick example of text classification:
import tailwiz
import pandas as pd
# Create a pandas DataFrame of labeled text. The 'label'
# column contains 'mean' or 'nice' as labels for each text.
labeled_examples = pd.DataFrame(
[
['You make me vomit', 'mean'],
['Love you lots', 'nice'],
['You are the best', 'nice'],
],
columns=['text', 'label'],
)
# Create a pandas DataFrame of text to be classified by tailwiz.
# This DataFrame does not have a 'label' column. The labels here
# will be created by tailwiz.
to_classify = pd.DataFrame(
['Have a great day', 'I hate you'],
columns=['text'],
)
# Classify text using labeled_examples as reference data.
results = tailwiz.classify(
to_classify,
labeled_examples=labeled_examples,
)
# The results are a copy of text with a new column populated
# with AI-generated labels.
print(results)
Installation
Install tailwiz through pip by entering the following into command line:
python -m pip install --upgrade tailwiz
Usage
In this section, we outline the three main functions of tailwiz and provide examples.
tailwiz.classify(to_classify, labeled_examples, output_metrics=False, data_split_seed=None)
Given text, classify the text.
Parameters:
to_classify: pandas.DataFrame with a column named'text'(str). Text to be classified.labeled_examples: pandas.DataFrame with columns named'text'(str) and'label'(str,int). Labeled examples to enhance the performance of the classification task. The classified text is in the'text'column and the text's labels are in the'label'column.output_metrics: bool, default False. Whether to outputperformance_estimatetogether with results in a tuple.data_split_seed: int, default None. Controls the shuffling oflabeled_examplesfor internal training and evaluation of language models. Settingdata_split_seedto be an integer ensures reproducible results.
Any additional keyword arguments will override tailwiz.classify's training arguments, specifically scikit-learn's LogisticRegression parameters.
Returns:
results: pandas.DataFrame. A copy ofto_classifywith a new column,'tailwiz_label', containing classification results.performance_estimate: Dict[str, float]. Dictionary of metric name to metric value mappings. Included together with results in a tuple ifoutput_metricsis True. Useslabeled_examplesto give an estimate of the accuracy of the classification.
Example:
import tailwiz
import pandas as pd
df_to_classify = pd.DataFrame(
['Have a great day', 'I hate you'],
columns=['text'],
)
df_labeled_examples = pd.DataFrame(
[
['You make me vomit', 'mean'],
['Love you lots', 'nice'],
['You are the best', 'nice'],
],
columns=['text', 'label'],
)
results = tailwiz.classify(
to_classify=df_to_classify,
labeled_examples=df_labeled_examples,
)
print(results)
tailwiz.parse(to_parse, labeled_examples=None, output_metrics=False, data_split_seed=None)
Given a prompt and a context, parse the answer from the context.
Parameters:
to_parse: pandas.DataFrame with columns named'context'(str) and'prompt'(str). Labels will be parsed directly from contexts in'context'according to the prompts in'prompt'.labeled_examples: pandas.DataFrame with columns named'context'(str),'prompt'(str), and'label'(str), default None. Labeled examples to enhance the performance of the parsing task. The labels in'label'must be extracted exactly from the contexts in'context'(as whole words) according to the prompts in'prompt'.output_metrics: bool, default False. Whether to outputperformance_estimatetogether with results in a tuple.data_split_seed: int, default None. Controls the shuffling oflabeled_examplesfor internal training and evaluation of language models. Settingdata_split_seedto be an integer ensures reproducible results.
Any additional keyword arguments will override tailwiz.parse's training arguments, specifically Hugging Face's TrainingArguments parameters.
Returns:
results: pandas.DataFrame. A copy ofto_parsewith a new column,'tailwiz_label', containing parsed results.performance_estimate: Dict[str, float]. Dictionary of metric name to metric value mappings. Included together with results in a tuple ifoutput_metricsis True. Useslabeled_examplesto give an estimate of the accuracy of the parsing job.
Example:
import tailwiz
import pandas as pd
df_to_parse = pd.DataFrame(
[['Extract the money.', 'Try to save at least £10']],
columns=['prompt', 'context'],
)
df_labeled_examples = pd.DataFrame(
[
['Extract the money.', 'He owed me $100', '$100'],
['Extract the money.', '¥5000 bills are common', '¥5000'],
['Extract the money.', 'Eggs rose to €5 this week', '€5'],
],
columns=['prompt', 'context', 'label'],
)
results = tailwiz.parse(
to_parse=df_to_parse,
labeled_examples=df_labeled_examples,
)
print(results)
tailwiz.generate(to_generate, labeled_examples=None, output_metrics=False, data_split_seed=None)
Given a prompt, generate an answer.
Parameters:
to_generate: pandas.DataFrame with a column named'prompt'(str). Prompts according to which labels will generated.labeled_examples: pandas.DataFrame with columns named'prompt'(str) and'label'(str), default None. Labeled examples to enhance the performance of the parsing task. The labels in'label'should be responses to the prompts in'prompt'.output_metrics: bool, default False. Whether to outputperformance_estimatetogether with results in a tuple.data_split_seed: int, default None. Controls the shuffling oflabeled_examplesfor internal training and evaluation of language models. Settingdata_split_seedto be an integer ensures reproducible results.
Any additional keyword arguments will override tailwiz.generate's training arguments, specifically Hugging Face's Seq2SeqTrainingArguments parameters.
Returns:
results: pandas.DataFrame. A copy ofto_generatewith a new column,'tailwiz_label', containing generated results.performance_estimate: Dict[str, float]. Dictionary of metric name to metric value mappings. Included together with results in a tuple ifoutput_metricsis True. Useslabeled_examplesto give an estimate of the accuracy of the text generation job.
Example:
import tailwiz
import pandas as pd
df_to_generate = pd.DataFrame(
['Label this sentence as "positive" or "negative": I am crying my eyes out.'],
columns=['prompt']
)
df_labeled_examples = pd.DataFrame(
[
['Label this sentence as "positive" or "negative": I love puppies!', 'positive'],
['Label this sentence as "positive" or "negative": I do not like you at all.', 'negative'],
['Label this sentence as "positive" or "negative": Love you lots.', 'positive'],
],
columns=['prompt', 'label']
)
results = tailwiz.generate(
to_generate=df_to_generate,
labeled_examples=df_labeled_examples,
)
print(results)
Templates (Notebooks)
Use these Jupyter Notebook examples as templates to help load your data and run any of the three tailwiz functions:
- For an example of
tailwiz.classify, seeexamples/classify.ipynb - For an example of
tailwiz.parse, seeexamples/parse.ipynb - For an example of
tailwiz.generate, seeexamples/generate.ipynb
Contact
Please contact Daniel Kang (ddkang [at] g.illinois.edu) and Timothy Dai (timdai [at] stanford.edu) if you decide to use tailwiz.
Release files for tailwiz 0.0.24
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tailwiz-0.0.24.tar.gz | 12.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tailwiz-0.0.24-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.5 kB
Release files / tailwiz-0.0.24.tar.gz
| Download URL | tailwiz-0.0.24.tar.gz |
|---|---|
| Size | 12.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
85ffb328e188e04077fd9863af0c1f2c1f30c76c60fa0f17594296dd330908de
|
|
BLAKE2b-256 checksum How to use checksums |
5a10d3537e86d56fffd08c90282bccf932860c12573fd9423eb78ee2327ff07d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.10.12
|
Release files / tailwiz-0.0.24-py3-none-any.whl
| Download URL | tailwiz-0.0.24-py3-none-any.whl |
|---|---|
| Size | 13.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3f4d22cb2d519071f7657d1b0c5e95134309eacd8fde2146b402289019a41e29
|
|
BLAKE2b-256 checksum How to use checksums |
3dc7cc73921ad9fcb51d11bc943c3bfad35209ed29b1d7c9093ef6adf297f174
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.10.12
|