from datasets import load_dataset | |
import matplotlib.pyplot as plt | |
from os.path import dirname, join | |
dataset = load_dataset("undertheseanlp/UTS_Text_v1") | |
sentences = dataset["train"]["text"] | |
# compute histogram of sentence lengths with bin size = 10 | |
pwd = dirname(__file__) | |
tmp = join(pwd, "tmp") | |
lengths = [len(s) for s in sentences] | |
plt.hist(lengths, bins=range(0, max(lengths), 10)) | |
# add title of plot | |
plt.title("Histogram of sentence lengths") | |
plt.savefig(join(tmp, "histogram.png")) | |
plt.show() | |