Spaces:
Build error

Enaks / enaks-tokenizer-code.py
foski234's picture
Upload 3 files
b455ad4 verified
Raw History Blame Contribute Delete
6.95 kB
import pandas as pd
from transformers import AutoTokenizer
from tokenizers import ByteLevelBPETokenizer
from pathlib import Path
# Step 1: Extract the text from Enaks documentation
# For now, we'll use a sample text from the document, you'd replace this with the full text
enaks_text = """
Enaks Cleaning Services is a professional cleaning company based in Atlanta. The company
is built on the foundation of integrity, reliability, and quality service, with a mission to provide
exceptional cleaning services that exceed client expectations.
Standard Cleaning Services:
- Dusting of all surfaces including furniture, fixtures, and decor
- Vacuuming of all floors, carpets, and rugs
- Mopping of all hard surface floors
- Cleaning and sanitizing of bathrooms including toilets, sinks, and showers
- Kitchen cleaning including countertops, sinks, and appliance exteriors
- Emptying trash and replacing liners
- Spot cleaning of walls, light switches, and door handles
Deep Cleaning Services:
- Includes all standard cleaning tasks plus more intensive cleaning
- Detailed cleaning of baseboards, crown molding, and door frames
- Interior window cleaning
- Cleaning inside cabinets and drawers
- Detailed appliance cleaning (inside and out)
- Removal of scale and soap scum from bathroom fixtures
- Cleaning of light fixtures and ceiling fans
Move-In/Move-Out Cleaning:
- Comprehensive cleaning of vacant properties
- Detailed cleaning of all surfaces, fixtures, and appliances
- Special attention to areas that may have been neglected
- Preparation of spaces for new occupants or final inspections
Industry Specializations:
- Commercial Office Spaces
- Medical Facilities
- Retail Establishments
- Educational Institutions
Unique Selling Points:
- Personalized Service: Customized cleaning plans tailored to each client's specific needs
- Attention to Detail: Meticulous approach to cleaning that ensures no area is overlooked
- Reliability: Consistent, dependable service that clients can count on
- Quality Assurance: Rigorous quality control measures to ensure consistent excellence
- Trained Professionals: Staff who are thoroughly trained in proper cleaning techniques
- Customer-Centric Approach: Strong focus on client satisfaction and building relationships
"""
# Save this to a file for the tokenizer to read
with open('enaks_data.txt', 'w') as f:
f.write(enaks_text)
# Step 2: Train a custom tokenizer from scratch
# This approach is good when you have industry-specific terminology
def train_custom_tokenizer():
# Initialize a tokenizer
tokenizer = ByteLevelBPETokenizer()
# Prepare the paths to the training files
paths = [str(x) for x in Path(".").glob("enaks_data.txt")]
# Train the tokenizer
tokenizer.train(
files=paths,
vocab_size=5000, # Start small for a specialized vocabulary
min_frequency=2, # Only include terms that appear at least twice
special_tokens=["<s>", "<pad>", "</s>", "<unk>", "<mask>"]
)
# Save the tokenizer
tokenizer.save_model("enaks_tokenizer")
print("Custom tokenizer trained and saved!")
return tokenizer
# Step 3: Alternatively, adapt an existing tokenizer (faster for small datasets)
def adapt_existing_tokenizer():
# Start with a pre-trained tokenizer
base_tokenizer = AutoTokenizer.from_pretrained("gpt2")
# Create a list of special cleaning industry terms from the Enaks document
special_tokens = [
"deep cleaning",
"move-in/move-out",
"post-construction",
"sanitizing",
"commercial office",
"medical facilities",
"retail establishments",
"educational institutions",
"quality assurance",
"attention to detail"
]
# Add the special tokens
num_added_tokens = base_tokenizer.add_tokens(special_tokens)
print(f"Added {num_added_tokens} tokens to the vocabulary")
# Save the adapted tokenizer
base_tokenizer.save_pretrained("enaks_adapted_tokenizer")
print("Adapted tokenizer saved!")
return base_tokenizer
# Step 4: Test the tokenizer on Enaks-specific content
def test_tokenizer(tokenizer_path="enaks_adapted_tokenizer"):
# Load the tokenizer
tokenizer = AutoTokenizer.from_pretrained(tokenizer_path)
# Test phrases specific to Enaks
test_phrases = [
"We provide deep cleaning services for medical facilities",
"Our move-in/move-out cleaning includes detailed appliance cleaning",
"Enaks Cleaning Services specializes in post-construction cleaning",
"We focus on attention to detail in all our cleaning processes"
]
# Tokenize and print results
for phrase in test_phrases:
tokens = tokenizer.tokenize(phrase)
print(f"\nPhrase: {phrase}")
print(f"Tokenized into: {tokens}")
print(f"Number of tokens: {len(tokens)}")
return tokenizer
# Step 5: Prepare training data for a model
def prepare_training_data():
# In a real scenario, you'd have much more data
# We're using a small sample for illustration
# Create a dataframe with Enaks service descriptions
data = [
{"service": "Standard Cleaning", "description": "Regular cleaning maintenance including dusting, vacuuming, and sanitizing."},
{"service": "Deep Cleaning", "description": "Intensive cleaning of all surfaces including baseboards, cabinets, and appliances."},
{"service": "Move-In/Move-Out", "description": "Comprehensive cleaning of vacant properties for new occupants or inspections."},
{"service": "Post-Construction", "description": "Removal of construction debris and cleaning of all surfaces affected by construction."},
{"service": "Commercial", "description": "Tailored cleaning solutions for businesses with flexible scheduling options."},
{"service": "Medical Facilities", "description": "Specialized cleaning following infection control protocols for healthcare environments."}
]
df = pd.DataFrame(data)
# Save to CSV for training
df.to_csv("enaks_services.csv", index=False)
print("Training data prepared and saved to CSV!")
return df
# Main execution
if __name__ == "__main__":
print("Starting Enaks Cleaning Services tokenizer training process...")
# Option 1: Train a custom tokenizer from scratch (better for larger datasets)
# train_custom_tokenizer()
# Option 2: Adapt an existing tokenizer (faster for small datasets)
tokenizer = adapt_existing_tokenizer()
# Test the tokenizer
test_tokenizer()
# Prepare sample training data
prepare_training_data()
print("\nNext steps:")
print("1. Use this tokenizer with a model like GPT-2 or BERT")
print("2. Fine-tune the model on your complete Enaks documentation")
print("3. Test generating content in Enaks' brand voice and terminology")