CoolFace
Apppublic

ramouch/Tunisian-Encoder

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
App README

πŸ‡ΉπŸ‡³ Tunisian Arabic Sentence Encoder API

This Space serves an embedding API for Tunisian Arabic medical dialogue using a fine-tuned version of AraBERT. It is designed to encode Tunisian dialect text into vector embeddings suitable for downstream NLP tasks such as similarity search or classification.


πŸš€ Features

  • β€”πŸ”₯ Fast inference with a fine-tuned Arabic BERT (original_model.pt)
  • β€”πŸ“¦ REST API with /encode endpoint
  • β€”πŸ³ Deployable via Docker on Hugging Face Spaces
  • β€”πŸ©Ί Designed for semantic search, text matching, and classification in Tunisian Arabic

πŸ“ Project Structure


.
β”œβ”€β”€ app.py                   # FastAPI app with /encode endpoint
β”œβ”€β”€ encoder.py               # Loads and wraps the SentenceTransformer model
β”œβ”€β”€ original\_model.pt        # Fine-tuned SentenceTransformer model
β”œβ”€β”€ requirements.txt         # Python dependencies
└── Dockerfile               # Dockerfile for Hugging Face Spaces

🌐 API Endpoints

βœ… Health Check


GET /

Response

json
{"status": "ok"}

πŸ”€ Embedding Text

POST /encode
Content-Type: application/json

Example Request:

json
{
  "text": "Ψ΄Ω†ΩˆΨ© Ψ£ΨΉΨ±Ψ§ΨΆ Ψ’Ω„Ψ§Ω… Ψ§Ω„Ψ±ΩƒΨ¨Ψ©ΨŸ"
}

Example Response:

json
{
  "embedding": [0.234, -0.982, ...]
}

πŸ“¦ Requirements

Installed automatically via requirements.txt:

txt
fastapi
uvicorn
torch
numpy
sentence-transformers

🧠 About the Model

The model is a fine-tuned version of `aubmindlab/bert-base-arabertv2` using the SentenceTransformers framework. It was trained on a Tunisian Arabic medical dialogue dataset, making it ideal for:

  • β€”πŸ©Ί Doctor-patient chatbot embedding
  • β€”πŸ§  Semantic similarity and clustering
  • β€”πŸ”Ž Intent recognition and search

Embedding size: 768 Format: PyTorch serialized model (original_model.pt)


🐳 Deploy on Hugging Face Spaces (Docker)

This app is deployed on Hugging Face Spaces with Docker:

dockerfile
# Use a minimal base image
FROM python:3.9-slim

# Create a non-root user for security
RUN useradd -m user
USER user

# Set environment variables
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH \
    PORT=7860

# Set the working directory
WORKDIR $HOME/app

# Copy requirements and install dependencies in a single RUN command
COPY --chown=user requirements.txt ./
RUN pip install --upgrade pip && \
    pip install -r requirements.txt

# Copy application files and the model
COPY --chown=user ./ $HOME/app

# Expose the correct port for Hugging Face Spaces
EXPOSE 7860

# Run the FastAPI app with uvicorn directly for lightweight deployment
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]

πŸ”§ Local Testing

To test locally with Docker:

bash
docker build -t arabic-bert-api .
docker run -p 7860:7860 arabic-bert-api

πŸ“‹ Example Python Client

python
import requests

url = "http://localhost:7860/encode"
response = requests.post(url, json={"text": "ΨΉΩ†Ψ―ΩŠ وجيعة في ΨΈΩ‡Ψ±ΩŠ"})
print(response.json())

πŸ‘©β€πŸ’» Maintainer

Inherited Games Studio πŸ“§ contact@inheritedgames.com πŸ”— github.com/inheritedgames πŸ”— github.com/RAMA012001


πŸ“„ License

MIT License