Views
No views yet
id2label = {0: "GenAI used for smart city application", 1: "Not related"}1import torch
2from transformers import DebertaV2Tokenizer, AutoModelForSequenceClassification
3
4MODEL_ID = "joaocarlosnb/genai-smartcity-classifier" # replace with actual repo id
5TEMP = 0.602
6id2label = {0: "GenAI used for smart city application", 1: "Not related"}
7
8tokenizer = DebertaV2Tokenizer.from_pretrained(MODEL_ID)
9model = AutoModelForSequenceClassification.from_pretrained(MODEL_ID)
10model.eval()
11
12def predict(text, max_length=256, apply_temp=True):
13 inputs = tokenizer(text, truncation=True, padding="max_length",
14 max_length=max_length, return_tensors="pt")
15 with torch.no_grad():
16 logits = model(**inputs).logits
17 if apply_temp:
18 logits = logits / TEMP
19 probs = torch.softmax(logits, dim=-1)[0]
20 top = int(probs.argmax())
21 return {
22 "label": id2label[top],
23 "probabilities": {id2label[i]: float(p) for i, p in enumerate(probs)}
24 }
25
26print(predict("We apply a diffusion model to simulate traffic for urban planning."))pip install transformers torchseed=42. Use DebertaV2Tokenizer with max_length=512 for full retraining.Bittencourt, J. C. N., Flores, T. K. S., Jesus, T. C., & Costa, D. G. (2025). On the Role of AI in Building Generative Urban Intelligence. In Review. https://doi.org/10.21203/rs.3.rs-7131966/v1