Team Ai
Modelpublic

thealper2/xlm-roberta-base-text-geolocation

sourceHugging Facemitupdated 23d agoView on Hugging Face
0likes129downloads
Model Card

xlm-roberta-base-text-geolocation

FacebookAI/xlm-roberta-base fine-tuned end-to-end for multiclass classification of short social-media text into one of 123 geographic regions. Output is a region label with a probability distribution; the model does not predict coordinates.

Labels

yachay/text_coordinates_regions contains one JSON file per region (c_0.json … c_122.json) and no region names. Labels are these file ids (c_0 … c_122). For orientation, the table at the end lists the empirical medoid of each region's training coordinates (descriptive statistic, not an official region definition).

Data

  • —Source: yachay/text_coordinates_regions @ b9fa48181e3c93791d0613382c77aeb91214f324, 615,000 posts, 5,000 per region (balanced). Coordinates are place-level (≈12k distinct points).
  • —Model input: text only. Coordinates are used for evaluation only.
  • —Preprocessing: strip, lower-case (corpus is already lower-cased), URLs → HTTPURL. Mentions, hashtags, emoji and place names are kept.
FilterRemovedReason
nullorempty0No text or no label: unusable.
malformed_coordinates0Coordinates not two numbers in valid range.
url_only12,911Text consists only of t.co links; the hash has no textual content.
duplicatetextregion1,286Identical text with identical label: keep one copy.

Remaining: 600,803 posts (2.31% removed).

  • —Split: 480,496 / 60,103 / 60,204 (train / validation / test), stratified by region, seed 42.
  • —Leakage control: posts that are identical after removing URLs and collapsing whitespace form a group (4,776 multi-post groups) and are assigned to a single split. Exact-text and group overlap between splits: 0.

Training

ParameterValue
Base modelFacebookAI/xlm-roberta-base
Headlinear classification head (XLMRobertaForSequenceClassification)
Losscross-entropy (no class weighting; classes are balanced)
Max sequence length256 (99.95% of posts are ≤ 256 tokens)
OptimizerAdamW (fused), weight decay 0.01
Learning rate2e-05, linear schedule, warmup ratio 0.1
Epochs3.0
Batch size32 × 1 accumulation = 32
Gradient clipping1.0
Precisionbf16
Paddingdynamic
Model selectionbest validation macro_f1 (evaluated each epoch)
Seed42
HardwareNVIDIA GeForce RTX 5060 Ti
Training time1.27 h
Softwaretorch 2.11.0+cu128, transformers 5.17.0, datasets 4.3.0

Evaluation

Classification (60,204 test posts):

MetricValidationTestTF-IDF + LR (test)
Accuracy (top-1)24.5624.3427.35
Top-3 accuracy44.8845.0445.89
Top-5 accuracy56.1156.1255.76
Macro F123.2122.9526.81
Weighted F123.1322.8626.72
Macro precision25.8025.2327.51
Macro recall24.6324.4327.44

Geographic distance (test). Distance between the post's coordinate and the medoid of the predicted region. "Oracle" uses the medoid of the true region, i.e. the floor for a perfect classifier under this representation.

MetricModelOracle
Median distance to predicted region medoid (km)1264181
Mean distance (km)3126272
Acc@161 km12.7346.54
Acc@500 km27.2787.62
Acc@1000 km44.0196.42
Acc@2500 km66.6899.46

Usage

python
from transformers import pipeline

clf = pipeline("text-classification", model="thealper2/xlm-roberta-base-text-geolocation", top_k=5)
print(clf("just landed at jfk, the traffic in queens is already insane"))

Apply the training preprocessing (lower-case, URLs → HTTPURL) for best results; settings are stored in preprocessing.json.

Limitations

  • —Region labels are unnamed dataset clusters; regions have unequal geographic extent.
  • —Coordinates in the source data are place-level, so distance metrics are coarse.
  • —Twitter data from 2021: topical, demographic and platform biases; performance on other domains or periods is not measured.
  • —Many posts carry no geographic signal (emoji-only, generic replies); confidence is low for these.
  • —Some posts contain explicit place names from app templates (check-ins, "just posted a photo @ …"), which are easy cases.

Per-region results (test)

RegionMedoid latMedoid lonMedian km to medoidF1
c_040.56-75.062510.055
c_152.72-1.351980.121
c_235.61137.771890.356
c_3-22.29-43.552570.035
c_434.59-83.213090.027
c_540.24-3.533570.180
c_633.96-117.851240.045
c_741.61-85.252420.017
c_8-28.24-50.832720.086
c_928.7376.832340.095
c_1045.719.432800.036
c_1134.02-95.642700.034
c_1239.7129.712580.355
c_13-6.53107.852010.291
c_14-34.72-58.922970.150
c_1527.57-81.031510.101
c_1619.43-98.791210.163
c_1724.9947.322850.266
c_183.22101.961310.421
c_1914.57120.941100.377
c_204.84-74.151420.188
c_2130.25-91.742730.122
c_2233.47130.741200.414
c_2326.5582.892180.338
c_2419.5273.141860.234
c_2529.69-98.632120.080
c_2652.217.681810.581
c_2730.4632.602340.280
c_2811.9178.232420.462
c_29-8.19-35.311420.060
c_3045.80-122.361800.097
c_31-33.61-70.97600.208
c_3229.3447.95600.327
c_3342.60141.791340.352
c_3413.51100.38720.462
c_356.513.081210.205
c_36-15.77-48.591810.042
c_3738.26-121.97680.037
c_3839.97-90.591830.044
c_3924.4355.512060.148
c_40-1.1236.231360.233
c_4140.8314.201810.585
c_42-25.6428.25820.119
c_439.788.481890.258
c_4439.39-105.17720.077
c_4518.39-68.932170.162
c_46-2.20-78.772120.272
c_4721.7538.97790.132
c_48-32.40152.525410.138
c_4932.36-110.911470.034
c_5014.57-89.132010.073
c_5123.2988.222190.341
c_5216.22103.143230.132
c_537.59-4.064110.240
c_5421.04-103.481210.034
c_5544.6320.192460.651
c_5651.1419.082410.670
c_579.70123.981470.324
c_5838.59-9.321240.243
c_5930.4730.081830.360
c_60-1.12-48.36600.071
c_6145.36-93.331210.090
c_62-28.3724.25610.099
c_63-20.66-48.681790.012
c_646.46125.291250.075
c_6542.9728.212430.338
c_66-8.69114.901210.204
c_67-25.52-57.66690.139
c_688.63-79.791210.144
c_6924.84122.002660.528
c_7010.26-74.731240.162
c_71-7.61112.44770.367
c_72-40.10-70.883170.065
c_73-28.75-64.773020.107
c_7410.26-67.571210.205
c_75-37.81144.80600.158
c_7611.90-61.943070.033
c_7725.91-100.14600.131
c_78-13.07-38.36620.145
c_7947.30-0.341990.481
c_80-29.9930.641840.305
c_815.428.002190.116
c_8220.5982.801670.283
c_8336.9835.291450.262
c_84-0.03115.383870.195
c_8537.18-122.0100.123
c_8639.6741.672120.296
c_87-22.82-52.602190.153
c_88-2.75-58.73600.046
c_8953.7449.527840.601
c_90-16.3831.454220.219
c_9137.26126.75610.833
c_92-1.6729.194590.350
c_93-3.84-38.17830.125
c_9440.53116.2811310.636
c_95-3.29-43.561390.070
c_9633.6272.911660.142
c_9723.3078.191120.286
c_9817.3478.661720.376
c_9920.52-88.011550.128
c_10048.52-114.053910.189
c_10142.432.42790.458
c_10249.03-122.8800.142
c_10359.8118.851940.616
c_10425.5067.871040.483
c_1056.47100.201280.127
c_106-17.96-40.221810.082
c_10741.57-96.11740.132
c_108-6.5739.09610.547
c_109-22.3823.831810.222
c_110-10.33-64.284110.040
c_111-11.95-75.81600.196
c_11240.44-112.08660.091
c_11318.9497.021210.605
c_11444.36-68.612520.078
c_11518.38-76.93670.163
c_11641.3236.541470.024
c_117-8.18-48.453120.078
c_11855.95-4.681480.259
c_11956.0212.721680.389
c_12039.173.05610.188
c_12117.9343.542030.318
c_12237.0123.091200.729