ramouch/Tunisian-Encoder
πΉπ³ 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
/encodeendpoint - π³ 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
{"status": "ok"}π€ Embedding Text
POST /encode
Content-Type: application/jsonExample Request:
{
"text": "Ψ΄ΩΩΨ© Ψ£ΨΉΨ±Ψ§ΨΆ Ψ’ΩΨ§Ω
Ψ§ΩΨ±ΩΨ¨Ψ©Ψ"
}Example Response:
{
"embedding": [0.234, -0.982, ...]
}π¦ Requirements
Installed automatically via requirements.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:
# 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:
docker build -t arabic-bert-api .
docker run -p 7860:7860 arabic-bert-apiπ Example Python Client
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
