x
float64
-88.35
82
y
float64
-86.35
88.7
language
stringlengths
3
19
corpus
stringlengths
3
59
-18.28238
-2.315064
Marathi
opus100
-64.574786
-6.972784
Marathi
opus100
-55.588644
0.740308
Marathi
opus100
30.174092
28.561195
Marathi
pib
-16.8444
-0.429286
Marathi
pib
-13.992644
0.70737
Marathi
pib
-13.451096
17.680722
Marathi
pib
-67.07903
-1.450883
Marathi
pib
30.683829
27.999965
Marathi
pib
2.293134
-50.560417
Marathi
pib
-14.71315
0.378662
Marathi
pib
-14.262408
-15.717909
Marathi
pib
29.225542
30.075136
Marathi
pib
-72.345372
-6.565703
Marathi
pib
-17.105466
-0.358465
Marathi
pib
30.709126
29.035129
Marathi
pib
1.898391
-53.309739
Marathi
pib
-13.889551
0.790806
Marathi
pib
2.152298
-53.526555
Marathi
pib
2.167264
-51.004306
Marathi
pib
-57.258285
-1.045722
Marathi
pib
-56.311582
-1.515933
Marathi
pib
-61.945088
4.567302
Marathi
pib
-14.361234
0.436886
Marathi
pib
3.126833
-51.392519
Marathi
pib
-57.749879
-1.494385
Marathi
pib
29.231269
29.155568
Marathi
pib
4.287004
-50.418744
Marathi
pib
-72.219699
-6.811074
Marathi
pib
36.055559
15.382714
Marathi
pib
30.532288
28.083667
Marathi
pib
33.849957
15.534781
Marathi
pib
-15.743342
0.505287
Marathi
pib
3.215276
-51.245484
Marathi
pib
-60.737007
-3.394126
Marathi
pib
31.007212
28.819507
Marathi
pib
2.989671
-51.270435
Marathi
pib
31.167064
28.286369
Marathi
pib
-14.748556
0.247347
Marathi
pib
1.963952
-51.834236
Marathi
pib
-74.551162
-18.237986
Marathi
pib
16.076539
9.587664
Marathi
pib
29.189616
30.146909
Marathi
pib
-16.437329
-1.168242
Marathi
pib
-20.385779
-22.657032
Marathi
pib
-17.694435
-1.679821
Marathi
pib
2.924035
-52.623346
Marathi
pib
4.370036
-50.332863
Marathi
pib
31.046874
29.276872
Marathi
pib
31.962588
8.722964
Marathi
pib
-72.106826
-7.067241
Marathi
pib
31.056858
28.393259
Marathi
pib
-50.119234
19.101274
Marathi
pib
-14.444092
-15.713925
Marathi
pib
-10.048824
19.417539
Marathi
pib
-67.977078
2.372236
Marathi
pib
-14.498362
0.401051
Marathi
pib
2.173073
-53.360564
Marathi
pib
30.477133
28.992233
Marathi
pib
47.8111
14.011303
Marathi
pib
-14.387866
-15.729387
Marathi
pib
-7.195896
-17.670195
Marathi
pib
2.667278
-52.891831
Marathi
pib
29.495611
29.168078
Marathi
pib
2.064402
-53.490421
Marathi
pib
3.372322
-51.308322
Marathi
pib
-13.354959
17.659825
Marathi
pib
49.659059
35.322728
Marathi
pib
4.06149
-50.583698
Marathi
pib
-62.895019
12.828384
Marathi
pib
-14.255674
0.493504
Marathi
pib
-72.11041
-7.06807
Marathi
pib
30.584932
29.276191
Marathi
pib
-14.43835
0.413504
Marathi
pib
-62.61876
4.063817
Marathi
pib
-6.433463
-15.836375
Marathi
pib
3.714367
-50.86134
Marathi
pib
-78.006012
14.291905
Marathi
pib
-54.048352
16.858531
Marathi
pib
4.433538
-50.245996
Marathi
pib
2.643019
-51.54507
Marathi
pib
31.122343
28.581803
Marathi
pib
4.102671
-36.52618
Marathi
pib
-15.612926
-0.968628
Marathi
pib
44.595938
12.468912
Marathi
pib
-57.052912
-0.911473
Marathi
pib
-15.182893
1.227909
Marathi
pib
3.443609
-51.095991
Marathi
pib
-72.072875
-6.644265
Marathi
pib
31.295764
29.176204
Marathi
pib
-55.628744
0.708347
Marathi
pib
2.249649
-50.192374
Marathi
pib
-14.8353
0.262177
Marathi
pib
28.440251
30.565329
Marathi
pib
2.552967
-51.897703
Marathi
pib
3.418963
-51.197725
Marathi
pib
-13.39446
17.752831
Marathi
pib
-15.661043
0.499482
Marathi
pib
30.39819
28.099538
Marathi
pib
-57.22444
1.737244
Marathi
pib

What follows is research code. It is by no means optimized for speed, efficiency, or readability.

Data loading, tokenizing and sharding

import os
import numpy as np
import pandas as pd
from sklearn.feature_extraction.text import TfidfTransformer
from sklearn.decomposition import TruncatedSVD
from tqdm.notebook import tqdm
from openTSNE import TSNE
import datashader as ds
import colorcet as cc


from dask.distributed import Client
import dask.dataframe as dd
import dask_ml
import dask.bag as db

from transformers import AutoTokenizer
from datasets import load_dataset
from datasets.utils.py_utils import convert_file_size_to_int


def batch_tokenize(batch):
    return {'tokenized': [' '.join(e.tokens) for e in tokenizer(batch['text']).encodings]} # "text" column hard encoded

# The original viz used a subset of the ROOTS Corpus.
# More info on the entire dataset here: https://huggingface.co/bigscience-data
# And here: https://arxiv.org/abs/2303.03915

dset = load_dataset(..., split="train")

dset = dset.map(batch_tokenize, batched=True, batch_size=64, num_proc=28)

dset_name = "roots_subset"
max_shard_size = convert_file_size_to_int('300MB')
dataset_nbytes = dset.data.nbytes
num_shards = int(dataset_nbytes / max_shard_size) + 1
num_shards = max(num_shards, 1)
print(f"Sharding into {num_shards} files.")
os.makedirs(f"{dset_name}/tokenized", exist_ok=True)
for shard_index in tqdm(range(num_shards)):
    shard = dset.shard(num_shards=num_shards, index=shard_index, contiguous=True)
    shard.to_parquet(f"{dset_name}/tokenized/tokenized-{shard_index:03d}.parquet")

Embedding

client = Client() # To keep track of dask computation
client

df = dd.read_parquet(f'{dset_name}/tokenized/')
vect = dask_ml.feature_extraction.text.CountVectorizer(tokenizer=str.split,
                                                       token_pattern=None,
                                                       vocabulary=vocab)
tokenized_bag = df['tokenized'].to_bag()
X = vect.transform(tokenized_bag)

counts = X.compute()
client.shutdown()

tfidf_transformer = TfidfTransformer(sublinear_tf=True, norm="l2")
tfidf = tfidf_transformer.fit_transform(counts)

svd = TruncatedSVD(n_components=160)
X_svd = svd.fit_transform(tfidf)

tsne = TSNE(
    perplexity=30, # not sure what param setting resulted in the plot
    n_jobs=28,
    random_state=42,
    verbose=True,
)

tsne_embedding = tsne.fit(X)

Plotting

df = pd.DataFrame(data=tsne_embedding, columns=['x','y'])
agg = ds.Canvas(plot_height=600, plot_width=600).points(df, 'x', 'y')
img = ds.tf.shade(agg, cmap=cc.fire, how='eq_hist')
ds.tf.set_background(img, "black")

ROOTS Dataset Scatterplot

Downloads last month
0
Edit dataset card