Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing py pi package #3

Merged
merged 10 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ ner_model_bert
*.pyc
.DS_Store
eclipse_ai.egg-info
dist
dist
local_build.md
63 changes: 48 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pip install eclipse-ai --upgrade
## Usage.

``` bash
usage: eclipse [-h] [-p PROMPT] [-f FILE] [-m MODEL_PATH] [-o OUTPUT] [--debug] [-d DELIMITER] [-g]
usage: eclipse [-h] [-p PROMPT] [-f FILE] [-m MODEL_PATH] [-o OUTPUT] [--debug] [-d DELIMITER] [-g] [-dir MODEL_DIRECTORY] [--line_by_line]

Entity recognition using BERT.

Expand All @@ -131,7 +131,9 @@ options:
-d DELIMITER, --delimiter DELIMITER
Delimiter to separate text inputs, defaults to newline.
-g, --use_gpu Enable GPU usage for model inference.

-dir MODEL_DIRECTORY, --model_directory MODEL_DIRECTORY
Directory where the BERT model should be downloaded and unzipped.
--line_by_line Process text line by line and yield results incrementally.
```

Here are some examples:
Expand All @@ -151,22 +153,53 @@ Additional Options
## Usage as a module

```python
from eclipse import process_text # Replace 'your_script_name' with the actual name of the script without '.py'

# Set the path to the pretrained BERT model. This should be the same as DEFAULT_MODEL_PATH in the script
model_path = "./ner_model_bert"
# Correct import based on your project structure
from eclipse import process_text

# Example text to process
model_path = "./ner_model_bert"
input_text = "Your example text here."

# Process the text
# The 'device' argument is either 'cpu' or 'cuda' depending on whether you are using CPU or GPU
processed_text, highest_avg_label, highest_avg_confidence, is_high_confidence = process_text(input_text, model_path, 'cpu')

print(f"Processed Text: {processed_text}")
print(f"Highest Average Label: {highest_avg_label}")
print(f"Highest Average Confidence: {highest_avg_confidence}")
print(f"Is High Confidence: {is_high_confidence}")
# Set this to True if you want to process the text line by line, or False to process all at once
line_by_line = False

try:
# Handle both line-by-line processing and whole text processing
if line_by_line:
# Process the text line by line
for result in process_text(input_text, model_path, "cpu", line_by_line=False):
# In line-by-line mode, result should not be None, but check to be safe
if result:
(
processed_text,
highest_avg_label,
highest_avg_confidence,
is_high_confidence,
) = result
print(f"Processed Text: {processed_text}")
print(f"Highest Average Label: {highest_avg_label}")
print(f"Highest Average Confidence: {highest_avg_confidence}")
print(f"Is High Confidence: {is_high_confidence}")
else:
print("Error: Empty result for a line.")
else:
# Process the entire text as a single block
result = process_text(input_text, model_path, "cpu", line_by_line=False)
if result:
(
processed_text,
highest_avg_label,
highest_avg_confidence,
is_high_confidence,
) = result
print(f"Processed Text: {processed_text}")
print(f"Highest Average Label: {highest_avg_label}")
print(f"Highest Average Confidence: {highest_avg_confidence}")
print(f"Is High Confidence: {is_high_confidence}")
else:
print("Error: Empty result for the text.")

except Exception as e: # Catching general exceptions
print(f"Error processing text: {e}")
```

## Understanding the Output
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[tool.ruff]
ignore = ["E501","E722"]
ignore = ["E501","E722","F401"]
fixable = ["ALL"]
1 change: 1 addition & 0 deletions src/eclipse/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .eclipse import process_text
Loading
Loading