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.
Filter Removed Reason
null_or_empty 0 No text or no label: unusable.
malformed_coordinates 0 Coordinates not two numbers in valid range.
url_only 12,911 Text consists only of t.co links; the hash has no textual content.
duplicate_text_region 1,286 Identical 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

Parameter Value
Base model FacebookAI/xlm-roberta-base
Head linear classification head (XLMRobertaForSequenceClassification)
Loss cross-entropy (no class weighting; classes are balanced)
Max sequence length 256 (99.95% of posts are ≤ 256 tokens)
Optimizer AdamW (fused), weight decay 0.01
Learning rate 2e-05, linear schedule, warmup ratio 0.1
Epochs 3.0
Batch size 32 × 1 accumulation = 32
Gradient clipping 1.0
Precision bf16
Padding dynamic
Model selection best validation macro_f1 (evaluated each epoch)
Seed 42
Hardware NVIDIA GeForce RTX 5060 Ti
Training time 1.27 h
Software torch 2.11.0+cu128, transformers 5.17.0, datasets 4.3.0

Evaluation

Classification (60,204 test posts):

Metric Validation Test TF-IDF + LR (test)
Accuracy (top-1) 24.56 24.34 27.35
Top-3 accuracy 44.88 45.04 45.89
Top-5 accuracy 56.11 56.12 55.76
Macro F1 23.21 22.95 26.81
Weighted F1 23.13 22.86 26.72
Macro precision 25.80 25.23 27.51
Macro recall 24.63 24.43 27.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.

Metric Model Oracle
Median distance to predicted region medoid (km) 1264 181
Mean distance (km) 3126 272
Acc@161 km 12.73 46.54
Acc@500 km 27.27 87.62
Acc@1000 km 44.01 96.42
Acc@2500 km 66.68 99.46

Usage

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)

Region Medoid lat Medoid lon Median km to medoid F1
c_0 40.56 -75.06 251 0.055
c_1 52.72 -1.35 198 0.121
c_2 35.61 137.77 189 0.356
c_3 -22.29 -43.55 257 0.035
c_4 34.59 -83.21 309 0.027
c_5 40.24 -3.53 357 0.180
c_6 33.96 -117.85 124 0.045
c_7 41.61 -85.25 242 0.017
c_8 -28.24 -50.83 272 0.086
c_9 28.73 76.83 234 0.095
c_10 45.71 9.43 280 0.036
c_11 34.02 -95.64 270 0.034
c_12 39.71 29.71 258 0.355
c_13 -6.53 107.85 201 0.291
c_14 -34.72 -58.92 297 0.150
c_15 27.57 -81.03 151 0.101
c_16 19.43 -98.79 121 0.163
c_17 24.99 47.32 285 0.266
c_18 3.22 101.96 131 0.421
c_19 14.57 120.94 110 0.377
c_20 4.84 -74.15 142 0.188
c_21 30.25 -91.74 273 0.122
c_22 33.47 130.74 120 0.414
c_23 26.55 82.89 218 0.338
c_24 19.52 73.14 186 0.234
c_25 29.69 -98.63 212 0.080
c_26 52.21 7.68 181 0.581
c_27 30.46 32.60 234 0.280
c_28 11.91 78.23 242 0.462
c_29 -8.19 -35.31 142 0.060
c_30 45.80 -122.36 180 0.097
c_31 -33.61 -70.97 60 0.208
c_32 29.34 47.95 60 0.327
c_33 42.60 141.79 134 0.352
c_34 13.51 100.38 72 0.462
c_35 6.51 3.08 121 0.205
c_36 -15.77 -48.59 181 0.042
c_37 38.26 -121.97 68 0.037
c_38 39.97 -90.59 183 0.044
c_39 24.43 55.51 206 0.148
c_40 -1.12 36.23 136 0.233
c_41 40.83 14.20 181 0.585
c_42 -25.64 28.25 82 0.119
c_43 9.78 8.48 189 0.258
c_44 39.39 -105.17 72 0.077
c_45 18.39 -68.93 217 0.162
c_46 -2.20 -78.77 212 0.272
c_47 21.75 38.97 79 0.132
c_48 -32.40 152.52 541 0.138
c_49 32.36 -110.91 147 0.034
c_50 14.57 -89.13 201 0.073
c_51 23.29 88.22 219 0.341
c_52 16.22 103.14 323 0.132
c_53 7.59 -4.06 411 0.240
c_54 21.04 -103.48 121 0.034
c_55 44.63 20.19 246 0.651
c_56 51.14 19.08 241 0.670
c_57 9.70 123.98 147 0.324
c_58 38.59 -9.32 124 0.243
c_59 30.47 30.08 183 0.360
c_60 -1.12 -48.36 60 0.071
c_61 45.36 -93.33 121 0.090
c_62 -28.37 24.25 61 0.099
c_63 -20.66 -48.68 179 0.012
c_64 6.46 125.29 125 0.075
c_65 42.97 28.21 243 0.338
c_66 -8.69 114.90 121 0.204
c_67 -25.52 -57.66 69 0.139
c_68 8.63 -79.79 121 0.144
c_69 24.84 122.00 266 0.528
c_70 10.26 -74.73 124 0.162
c_71 -7.61 112.44 77 0.367
c_72 -40.10 -70.88 317 0.065
c_73 -28.75 -64.77 302 0.107
c_74 10.26 -67.57 121 0.205
c_75 -37.81 144.80 60 0.158
c_76 11.90 -61.94 307 0.033
c_77 25.91 -100.14 60 0.131
c_78 -13.07 -38.36 62 0.145
c_79 47.30 -0.34 199 0.481
c_80 -29.99 30.64 184 0.305
c_81 5.42 8.00 219 0.116
c_82 20.59 82.80 167 0.283
c_83 36.98 35.29 145 0.262
c_84 -0.03 115.38 387 0.195
c_85 37.18 -122.01 0 0.123
c_86 39.67 41.67 212 0.296
c_87 -22.82 -52.60 219 0.153
c_88 -2.75 -58.73 60 0.046
c_89 53.74 49.52 784 0.601
c_90 -16.38 31.45 422 0.219
c_91 37.26 126.75 61 0.833
c_92 -1.67 29.19 459 0.350
c_93 -3.84 -38.17 83 0.125
c_94 40.53 116.28 1131 0.636
c_95 -3.29 -43.56 139 0.070
c_96 33.62 72.91 166 0.142
c_97 23.30 78.19 112 0.286
c_98 17.34 78.66 172 0.376
c_99 20.52 -88.01 155 0.128
c_100 48.52 -114.05 391 0.189
c_101 42.43 2.42 79 0.458
c_102 49.03 -122.88 0 0.142
c_103 59.81 18.85 194 0.616
c_104 25.50 67.87 104 0.483
c_105 6.47 100.20 128 0.127
c_106 -17.96 -40.22 181 0.082
c_107 41.57 -96.11 74 0.132
c_108 -6.57 39.09 61 0.547
c_109 -22.38 23.83 181 0.222
c_110 -10.33 -64.28 411 0.040
c_111 -11.95 -75.81 60 0.196
c_112 40.44 -112.08 66 0.091
c_113 18.94 97.02 121 0.605
c_114 44.36 -68.61 252 0.078
c_115 18.38 -76.93 67 0.163
c_116 41.32 36.54 147 0.024
c_117 -8.18 -48.45 312 0.078
c_118 55.95 -4.68 148 0.259
c_119 56.02 12.72 168 0.389
c_120 39.17 3.05 61 0.188
c_121 17.93 43.54 203 0.318
c_122 37.01 23.09 120 0.729
Downloads last month
16
Safetensors
Model size
0.3B params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for thealper2/xlm-roberta-base-text-geolocation

Finetuned
(4208)
this model

Dataset used to train thealper2/xlm-roberta-base-text-geolocation

Evaluation results