Skip to main content

Text processor with classification using DataBERT.

Project description

Textraer: Dataset Mention Detection in Documents

We introduce "textraer" which leverages a fine-tuned BERT model, specifically DataBERT, to identify sentences in documents that mention datasets. It's designed to process documents provided via URLs, extract text content sentence by sentence, and classify each sentence to determine whether it mentions a dataset.

Installation

Before using textraer, ensure you have all necessary dependencies installed. This project requires Python 3.x and the following Python libraries: transformers, datasets, nltk, PyPDF2, tqdm, and requests.

You can install these dependencies using pip:

pip install transformers datasets nltk PyPDF2 tqdm requests

Initialization

First, import DocumentProcessor from textraer and initialize it with the necessary parameters:

from textraer import DocumentProcessor

organization = 'your_huggingface_org'
json_cache_dir = './cache'
tokenizer_model = 'bert-base-uncased'
model_path = 'jamesliounis/DataBERT'

processor = DocumentProcessor(organization, json_cache_dir, tokenizer_model, model_path)

Replace 'your_huggingface_org' with your Hugging Face organization name and adjust the json_cache_dir, tokenizer_model, and model_path as needed.

Extracting and Classifying Text

From a PDF URL

To process a PDF document from a URL, extract its text content sentence by sentence, and classify each sentence, use the following methods:

pdf_url = 'https://arxiv.org/pdf/1706.03762.pdf'  # Example PDF URL
mode = 'sent'  # Extract text sentence by sentence

# Extract sentences from the PDF
sentences = processor.get_doc_from_url(pdf_url, mode)

# Classify each sentence
classifications = processor.classify(sentences)

# Print classification results
for sentence, classification in zip(sentences, classifications):
    print(f"Sentence: {sentence}")
    print(f"Classification: {classification}")

Creating a Dataset

If you want to create a dataset from the processed documents and push it to the Hugging Face Hub:

# Assuming 'sentences' contains your extracted sentences
processor.create_dataset(sentences, mode='sent')

This method will push the sentences as a dataset to your specified Hugging Face organization.

Understanding the Output

The classify method returns a list of dictionaries. Each dictionary contains two keys: 'label' and 'score'. The 'label' key can be either 'LABEL_0' or 'LABEL_1', where 'LABEL_1' indicates a mention of a dataset. The 'score' key provides the confidence level of the classification.

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

textraer-0.1.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

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

textraer-0.1.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file textraer-0.1.0.tar.gz.

File metadata

  • Download URL: textraer-0.1.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.15

File hashes

Hashes for textraer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3fee8ccb0e314182736cfb8c924cbe07a30cddf0bebe2a17d8b9550f047010e5
MD5 a77471a0225ada2030315e3ef6bc46d9
BLAKE2b-256 8650a0849101add523f08e6ceec539996cf39cd362e731423ee011c69a437cc6

See more details on using hashes here.

File details

Details for the file textraer-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: textraer-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.15

File hashes

Hashes for textraer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7a78b47b5f228ac058254763091ff1bedc1519a1460f5aac9ba4534e86dc66e3
MD5 b54a66a124efdb3d4bec2606f451e10e
BLAKE2b-256 aafebd5cc7360e0f69653ea658907cd6e9dd2444e4716d6f5c3eed3ee25f543f

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