Convert text to datasets
Project description
txt2dataset
A package for building, standardizing and validating datasets using language models. Supports normal API as well as batch API.
Models Supported
- Gemini
Installation
pip install txt2dataset
Usage
Schema
from pydantic import BaseModel
from typing import Optional, List
from datetime import datetime
class SingleDividend(BaseModel):
dividend_per_share: float
payment_date: Optional[datetime] = None
record_date: Optional[datetime] = None
stock_type_specified: Optional[str] = None
class DividendExtraction(BaseModel):
info_found: bool
data: List[SingleDividend] = []
Entries
Entries consist of an identifier and the text to be structured.
entries = [{'id':0, 'context':
"""First Business Financial Services, Inc. (the "Company") issued a press release today
announcing that the Company's Board of Directors declared a quarterly dividend of $0.18
per share on April 30, 2021, unchanged compared to the last quarterly dividend per share.
The dividend is payable on May 24, 2021 to shareholders of record on May 10, 2021.
Also on July 12, 2020 there was a payable dividend of $0.15 per share to shareholders
of record on July 1st, 2020."""},
{"id":1,"context": """XYZ Corp declared a dividend of $0.25 per share, payable June 15, 2021
to shareholders of record as of June 1, 2021."""}
]
Prompt
Choose a prompt such as:
prompt = "Extract ALL dividend information from this text"
Dataset Builder
Choose the requests per minute that work for your api key and model.
from txt2dataset import GeminiAPIBuilder
builder = GeminiAPIBuilder()
results = builder.build(prompt=prompt, schema=DividendExtraction, model="gemini-2.5-flash-lite",
entries=entries, rpm=4_000, tpm=4_000_000, rpm_threshold=0.75, tpm_threshold=0.75)
Result
| id | dividend_per_share | payment_date | record_date | stock_type_specified |
|---|---|---|---|---|
| 0 | 0.18 | 2021-05-24 00:00:00+00:00 | 2021-05-10 00:00:00+00:00 | quarterly |
| 0 | 0.15 | 2020-07-12 00:00:00+00:00 | 2020-07-01 00:00:00+00:00 | quarterly |
| 1 | 0.25 | 2021-06-15 00:00:00+00:00 | 2021-06-01 00:00:00+00:00 |
Spot Checking
Use spotcheck() to check if results look good. Highly recommended to use a more powerful model for spot checking, and cheap model for dataset generation.
spotchecks = builder.spotcheck(prompt=prompt, schema=DividendExtraction, model="gemini-2.5-flash", entries=entries,
results=results, sample_size = 10, rpm=4_000, tpm=4_000_000, rpm_threshold=0.75, tpm_threshold=0.75)
Result
| id | correct | desc |
|---|---|---|
| 1 | true | |
| 0 | false | The stock_type_specified for the $0.15 dividend is incorrectly listed as 'quarterly'; the source text does not explicitly state it for this particular dividend, so it should be null. |
Examples
See examples.
TODO
- handle errors
- spotcheck
- standardize
- store rate limits across multiple build commands
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file txt2dataset-0.5.4.tar.gz.
File metadata
- Download URL: txt2dataset-0.5.4.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9dc9fecd8200913bce97da0176fc7cfb9538bd991631934d0260e9f877c07de
|
|
| MD5 |
ef2e05f0318a11fdfaf2329f8bca7433
|
|
| BLAKE2b-256 |
d7866bbf4aedd1883209c84b423bdbeded3b7835c06a76deee33d8434766f3fb
|
File details
Details for the file txt2dataset-0.5.4-py3-none-any.whl.
File metadata
- Download URL: txt2dataset-0.5.4-py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ddefadbfd6c304023801cd1c805532657f4389a0d7ffdff92653c4228680d8ea
|
|
| MD5 |
901bb96c59953dda258eeb8524ab09e7
|
|
| BLAKE2b-256 |
e8bc248cb647dcc79a606cd07ce0679ba730a2c7b4fb20d69e27f88559079afa
|