Betisy-Detectena
1
1 language
—
by
Clemylia
Other
OTHER
New
0 downloads
Early-stage
Edge AI:
Mobile
Laptop
Server
Unknown
Mobile
Laptop
Server
Quick Summary
AI model with specialized capabilities.
Code Examples
==============================================================================texttransformers
# ==============================================================================
# CODE D'INFÉRENCE SIMPLIFIÉ POUR BETISY-DETECTENA
# Objectif : Charger le modèle PyTorch et prédire le label (0: Fait, 1: Bêtise)
# ==============================================================================
# --- 1. IMPORTS ET CONFIGURATION ---
import torch
import torch.nn as nn
import joblib
from huggingface_hub import hf_hub_download
from transformers import AutoTokenizer
# VOTRE IDENTIFIANT DE DÉPÔT HUGBING FACE
REPO_ID = "Clemylia/Betisy-Detectena"
# Hyperparamètres DÉFINITIFS de votre modèle (DOIVENT correspondre à l'entraînement)
EMBEDDING_DIM = 100
HIDDEN_DIM = 64
OUTPUT_DIM = 2
MAX_LEN = 30
MODEL_WEIGHTS_FILENAME = 'Betisy-Detectena_weights.pt'
TOKENIZER_FILENAME = 'Betisy-Detectena_tokenizer.joblib'
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
print(f"Périphérique d'inférence : {device}")
# --- 2. DÉFINITION DE L'ARCHITECTURE ---
class SimpleClassifier(nn.Module):
"""Architecture SimpleClassifier pour correspondre aux poids sauvegardés."""
def __init__(self, vocab_size, embedding_dim, hidden_dim, output_dim):
super(SimpleClassifier, self).__init__()
self.embedding = nn.Embedding(vocab_size, embedding_dim)
self.rnn = nn.LSTM(embedding_dim, hidden_dim, batch_first=True)
self.fc = nn.Linear(hidden_dim, output_dim)
def forward(self, input_ids):
embedded = self.embedding(input_ids)
output, (hidden, cell) = self.rnn(embedded)
return self.fc(hidden[-1])
# --- 3. FONCTION DE CHARGEMENT DU MODÈLE ---
def load_betisy_detectena(repo_id, weights_name, tokenizer_name, embed_dim, hidden_dim, output_dim, device):
"""Télécharge et charge le modèle complet depuis Hugging Face."""
# 3a. Téléchargement des fichiers
print("⏳ Téléchargement des fichiers depuis Hugging Face...")
weights_path = hf_hub_download(repo_id=repo_id, filename=weights_name)
tokenizer_path = hf_hub_download(repo_id=repo_id, filename=tokenizer_name)
# 3b. Chargement du Tokenizer
loaded_tokenizer = joblib.load(tokenizer_path)
VOCAB_SIZE = loaded_tokenizer.vocab_size
# 3c. Reconstruction et chargement des poids
model = SimpleClassifier(VOCAB_SIZE, embed_dim, hidden_dim, output_dim).to(device)
model.load_state_dict(torch.load(weights_path, map_location=device))
model.eval() # Mode inférence
print(f"✅ Modèle chargé avec {VOCAB_SIZE} tokens dans le vocabulaire.")
return model, loaded_tokenizer
# --- 4. FONCTION D'INFÉRENCE ---
def predict_betisy_detectena(text, model, tokenizer, max_len, device):
"""Prédit le label pour une seule phrase."""
# Tokenisation et préparation du tenseur
encoding = tokenizer.encode_plus(
text,
add_special_tokens=True,
max_length=max_len,
padding='max_length',
truncation=True,
return_tensors='pt',
)
input_ids = encoding['input_ids'].to(device)
# Inférence
with torch.no_grad():
outputs = model(input_ids)
probabilities = torch.softmax(outputs, dim=1)
confidence, prediction = torch.max(probabilities, dim=1)
label = "Absurdité (1) 🤡" if prediction.item() == 1 else "Fait Factuel (0) ✅"
return label, confidence.item()
# ==============================================================================
# CODE D'EXÉCUTION PRINCIPAL
# ==============================================================================
if __name__ == "__main__":
# CHARGEMENT (étape 1)
model, tokenizer = load_betisy_detectena(
REPO_ID,
MODEL_WEIGHTS_FILENAME,
TOKENIZER_FILENAME,
EMBEDDING_DIM,
HIDDEN_DIM,
OUTPUT_DIM,
device
)
print("\n--- TEST D'INFÉRENCE ---")
phrases_a_tester = [
"Le ciel est bleu.",
"Les cailloux peuvent parler en chantant des airs d'opéra.",
"Mars est la quatrième planète du système solaire.",
"Le temps s'est arrêté hier à 15h00 pour la sieste générale."
]
# PRÉDICTION (étape 2)
for phrase in phrases_a_tester:
label, confidence = predict_betisy_detectena(phrase, model, tokenizer, MAX_LEN, device)
print(f"-> '{phrase}'")
print(f" Prédiction : {label} (Confiance : {confidence*100:.2f}%)")==============================================================================texttransformers
# ==============================================================================
# CODE D'INFÉRENCE SIMPLIFIÉ POUR BETISY-DETECTENA
# Objectif : Charger le modèle PyTorch et prédire le label (0: Fait, 1: Bêtise)
# ==============================================================================
# --- 1. IMPORTS ET CONFIGURATION ---
import torch
import torch.nn as nn
import joblib
from huggingface_hub import hf_hub_download
from transformers import AutoTokenizer
# VOTRE IDENTIFIANT DE DÉPÔT HUGBING FACE
REPO_ID = "Clemylia/Betisy-Detectena"
# Hyperparamètres DÉFINITIFS de votre modèle (DOIVENT correspondre à l'entraînement)
EMBEDDING_DIM = 100
HIDDEN_DIM = 64
OUTPUT_DIM = 2
MAX_LEN = 30
MODEL_WEIGHTS_FILENAME = 'Betisy-Detectena_weights.pt'
TOKENIZER_FILENAME = 'Betisy-Detectena_tokenizer.joblib'
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
print(f"Périphérique d'inférence : {device}")
# --- 2. DÉFINITION DE L'ARCHITECTURE ---
class SimpleClassifier(nn.Module):
"""Architecture SimpleClassifier pour correspondre aux poids sauvegardés."""
def __init__(self, vocab_size, embedding_dim, hidden_dim, output_dim):
super(SimpleClassifier, self).__init__()
self.embedding = nn.Embedding(vocab_size, embedding_dim)
self.rnn = nn.LSTM(embedding_dim, hidden_dim, batch_first=True)
self.fc = nn.Linear(hidden_dim, output_dim)
def forward(self, input_ids):
embedded = self.embedding(input_ids)
output, (hidden, cell) = self.rnn(embedded)
return self.fc(hidden[-1])
# --- 3. FONCTION DE CHARGEMENT DU MODÈLE ---
def load_betisy_detectena(repo_id, weights_name, tokenizer_name, embed_dim, hidden_dim, output_dim, device):
"""Télécharge et charge le modèle complet depuis Hugging Face."""
# 3a. Téléchargement des fichiers
print("⏳ Téléchargement des fichiers depuis Hugging Face...")
weights_path = hf_hub_download(repo_id=repo_id, filename=weights_name)
tokenizer_path = hf_hub_download(repo_id=repo_id, filename=tokenizer_name)
# 3b. Chargement du Tokenizer
loaded_tokenizer = joblib.load(tokenizer_path)
VOCAB_SIZE = loaded_tokenizer.vocab_size
# 3c. Reconstruction et chargement des poids
model = SimpleClassifier(VOCAB_SIZE, embed_dim, hidden_dim, output_dim).to(device)
model.load_state_dict(torch.load(weights_path, map_location=device))
model.eval() # Mode inférence
print(f"✅ Modèle chargé avec {VOCAB_SIZE} tokens dans le vocabulaire.")
return model, loaded_tokenizer
# --- 4. FONCTION D'INFÉRENCE ---
def predict_betisy_detectena(text, model, tokenizer, max_len, device):
"""Prédit le label pour une seule phrase."""
# Tokenisation et préparation du tenseur
encoding = tokenizer.encode_plus(
text,
add_special_tokens=True,
max_length=max_len,
padding='max_length',
truncation=True,
return_tensors='pt',
)
input_ids = encoding['input_ids'].to(device)
# Inférence
with torch.no_grad():
outputs = model(input_ids)
probabilities = torch.softmax(outputs, dim=1)
confidence, prediction = torch.max(probabilities, dim=1)
label = "Absurdité (1) 🤡" if prediction.item() == 1 else "Fait Factuel (0) ✅"
return label, confidence.item()
# ==============================================================================
# CODE D'EXÉCUTION PRINCIPAL
# ==============================================================================
if __name__ == "__main__":
# CHARGEMENT (étape 1)
model, tokenizer = load_betisy_detectena(
REPO_ID,
MODEL_WEIGHTS_FILENAME,
TOKENIZER_FILENAME,
EMBEDDING_DIM,
HIDDEN_DIM,
OUTPUT_DIM,
device
)
print("\n--- TEST D'INFÉRENCE ---")
phrases_a_tester = [
"Le ciel est bleu.",
"Les cailloux peuvent parler en chantant des airs d'opéra.",
"Mars est la quatrième planète du système solaire.",
"Le temps s'est arrêté hier à 15h00 pour la sieste générale."
]
# PRÉDICTION (étape 2)
for phrase in phrases_a_tester:
label, confidence = predict_betisy_detectena(phrase, model, tokenizer, MAX_LEN, device)
print(f"-> '{phrase}'")
print(f" Prédiction : {label} (Confiance : {confidence*100:.2f}%)")Deploy This Model
Production-ready deployment in minutes
Together.ai
Instant API access to this model
Production-ready inference API. Start free, scale to millions.
Try Free APIReplicate
One-click model deployment
Run models in the cloud with simple API. No DevOps required.
Deploy NowDisclosure: We may earn a commission from these partners. This helps keep LLMYourWay free.