A package for working with data using NLP and ML.
Project description
structml
A package for working with data using NLP and ML.
Installation
Requirements: Python >=3.9 and Pytorch >=2.0.
To install the package from PyPI, run the following command:
pip install structml
To install the package from source, run the following command:
git clone https://github.com/PocketDocLabs/structml.git
cd structml
pip install .
Usage
line_heal
The line_heal module provides functions to heal strings of text that have been broken into multiple lines. This is useful for working with data that originates from a structured source, such as a PDF or a web page.
Functions
parse
Heals a string of text and returns the healed string.
def parse(string: str, verbose: bool = False, cuda: bool = True) -> str:
"""
Heal a broken line of text.
Args:
string (str): The broken string of text.
verbose (bool): Whether to print debug information.
cuda (bool): Whether to use the GPU for processing.
Returns:
str: The healed line of text.
"""
Example
from structml import line_heal
line = "This line is broken into mul-\ntiple lines as is common in data\nthat originates from a structured\nsource.\nThe goal of this function is to\nheal the line in a way flows\nnaturally and is easy to read."
healed_line = line_heal.parse(line)
print(healed_line)
Output
This line is broken into multiple lines as is common in data that originates from a structured source.
The goal of this function is to heal the line in a way flows naturally and is easy to read.
parse_list
Note: This function uses large amounts of memory. Heals a list of strings of text and returns the healed list. Uses multiple processes to speed up the healing process.
def parse_list(strings: List[str], verbose: bool = False, cuda: bool = True) -> List[str]:
"""
Heal a list of broken lines of text.
Args:
strings (List[str]): The list of broken strings of text.
verbose (bool): Whether to print debug information.
cuda (bool): Whether to use the GPU for processing.
Returns:
List[str]: The list of healed lines of text.
"""
Example
from structml import line_heal
lines = [
"This line is broken into mul-\ntiple lines as is common in data\nthat originates from a structured\nsource.\nThe goal of this function is to\nheal the line in a way flows\nnaturally and is easy to read.",
"Another goal of this function is to\ndo so in a way that is efficient\nand scalable."
]
healed_lines = line_heal.parse_list(lines)
for line in healed_lines:
print(line)
Output
This line is broken into multiple lines as is common in data that originates from a structured source.
The goal of this function is to heal the line in a way flows naturally and is easy to read.
Another goal of this function is to do so in a way that is efficient and scalable.
Credits
Thank you to Sebastian Gabarain for the model that Dans-StructureEvaluator is based on.
Model pages
- Dans-StructureEvaluator, used in the
line_healmodule. Used to check the perplexity of the text with various joining strategies.
License
This project is licensed under the terms of the AGPL-3.0 license. The full text of the license can be found in the LICENSE file.
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
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 structml-0.0.3.tar.gz.
File metadata
- Download URL: structml-0.0.3.tar.gz
- Upload date:
- Size: 17.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bcc6cad2f19b6c7bafe29e3076cd6344566b2f184ab42d10b8ebf01cefe809a7
|
|
| MD5 |
6cc741b254966119c1983eef577ed6a7
|
|
| BLAKE2b-256 |
c6116724562dee6fed9c3e44093c8e1c57eb0bc9096454b676831a917219625a
|
File details
Details for the file structml-0.0.3-py3-none-any.whl.
File metadata
- Download URL: structml-0.0.3-py3-none-any.whl
- Upload date:
- Size: 17.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7c105432672b53f96e25faf070c11232cabfac3ef98ba84c54b491b1fd54da6
|
|
| MD5 |
ae0b5790c79edd839914042dc86eb593
|
|
| BLAKE2b-256 |
a4b961fc0ec35b89c2a0be20853c686310f315ebeb3ef3a673eff067d3e183db
|