Commit ·
8b2dd6b
1
Parent(s): ac5d75e
Upload stan_large.py
Browse files- stan_large.py +98 -0
stan_large.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""STAN large dataset as corrected by Maddela et al.."""
|
| 2 |
+
|
| 3 |
+
import datasets
|
| 4 |
+
import pandas as pd
|
| 5 |
+
import pickle
|
| 6 |
+
|
| 7 |
+
_CITATION = """
|
| 8 |
+
@inproceedings{maddela-etal-2019-multi,
|
| 9 |
+
title = "Multi-task Pairwise Neural Ranking for Hashtag Segmentation",
|
| 10 |
+
author = "Maddela, Mounica and
|
| 11 |
+
Xu, Wei and
|
| 12 |
+
Preo{\c{t}}iuc-Pietro, Daniel",
|
| 13 |
+
booktitle = "Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics",
|
| 14 |
+
month = jul,
|
| 15 |
+
year = "2019",
|
| 16 |
+
address = "Florence, Italy",
|
| 17 |
+
publisher = "Association for Computational Linguistics",
|
| 18 |
+
url = "https://aclanthology.org/P19-1242",
|
| 19 |
+
doi = "10.18653/v1/P19-1242",
|
| 20 |
+
pages = "2538--2549",
|
| 21 |
+
abstract = "Hashtags are often employed on social media and beyond to add metadata to a textual utterance with the goal of increasing discoverability, aiding search, or providing additional semantics. However, the semantic content of hashtags is not straightforward to infer as these represent ad-hoc conventions which frequently include multiple words joined together and can include abbreviations and unorthodox spellings. We build a dataset of 12,594 hashtags split into individual segments and propose a set of approaches for hashtag segmentation by framing it as a pairwise ranking problem between candidate segmentations. Our novel neural approaches demonstrate 24.6{\%} error reduction in hashtag segmentation accuracy compared to the current state-of-the-art method. Finally, we demonstrate that a deeper understanding of hashtag semantics obtained through segmentation is useful for downstream applications such as sentiment analysis, for which we achieved a 2.6{\%} increase in average recall on the SemEval 2017 sentiment analysis dataset.",
|
| 22 |
+
}
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
_DESCRIPTION = """
|
| 26 |
+
The description below was taken from the paper "Multi-task Pairwise Neural Ranking for Hashtag Segmentation"
|
| 27 |
+
by Maddela et al..
|
| 28 |
+
|
| 29 |
+
"STAN large, our new expert curated dataset, which includes all 12,594 unique English hashtags and their
|
| 30 |
+
associated tweets from the same Stanford dataset.
|
| 31 |
+
|
| 32 |
+
STAN small is the most commonly used dataset in previous work. However, after reexamination, we found annotation
|
| 33 |
+
errors in 6.8% of the hashtags in this dataset, which is significant given that the error rate of the state-of-the art
|
| 34 |
+
models is only around 10%. Most of the errors were related to named entities. For example, #lionhead,
|
| 35 |
+
which refers to the “Lionhead” video game company, was labeled as “lion head”.
|
| 36 |
+
|
| 37 |
+
We therefore constructed the STAN large dataset of 12,594 hashtags with additional quality control for human annotations."
|
| 38 |
+
"""
|
| 39 |
+
_URLS = {
|
| 40 |
+
"train": "https://github.com/prashantkodali/HashSet/raw/master/datasets/stan-large-maddela_et_al_train.pkl",
|
| 41 |
+
"dev": "https://github.com/prashantkodali/HashSet/raw/master/datasets/stan-large-maddela_et_al_dev.pkl",
|
| 42 |
+
"test": "https://github.com/prashantkodali/HashSet/raw/master/datasets/stan-large-maddela_et_al_test.pkl"
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
class StanLarge(datasets.GeneratorBasedBuilder):
|
| 46 |
+
|
| 47 |
+
VERSION = datasets.Version("1.0.0")
|
| 48 |
+
|
| 49 |
+
def _info(self):
|
| 50 |
+
return datasets.DatasetInfo(
|
| 51 |
+
description=_DESCRIPTION,
|
| 52 |
+
features=datasets.Features(
|
| 53 |
+
{
|
| 54 |
+
"index": datasets.Value("int32"),
|
| 55 |
+
"hashtag": datasets.Value("string"),
|
| 56 |
+
"segmentation": datasets.Value("string"),
|
| 57 |
+
"alternatives": datasets.Sequence(
|
| 58 |
+
{
|
| 59 |
+
"segmentation": datasets.Value("string")
|
| 60 |
+
}
|
| 61 |
+
)
|
| 62 |
+
}
|
| 63 |
+
),
|
| 64 |
+
supervised_keys=None,
|
| 65 |
+
homepage="https://github.com/mounicam/hashtag_master",
|
| 66 |
+
citation=_CITATION,
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
def _split_generators(self, dl_manager):
|
| 70 |
+
downloaded_files = dl_manager.download(_URLS)
|
| 71 |
+
return [
|
| 72 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"] }),
|
| 73 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"] }),
|
| 74 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"] }),
|
| 75 |
+
]
|
| 76 |
+
|
| 77 |
+
def _generate_examples(self, filepath):
|
| 78 |
+
|
| 79 |
+
def get_segmentation(row):
|
| 80 |
+
return row["goldtruths"][0]
|
| 81 |
+
|
| 82 |
+
def get_alternatives(row):
|
| 83 |
+
segmentations = [{
|
| 84 |
+
"segmentation": x
|
| 85 |
+
} for x in row["goldtruths"]]
|
| 86 |
+
|
| 87 |
+
return segmentations[1:]
|
| 88 |
+
|
| 89 |
+
with open(filepath, 'rb') as f:
|
| 90 |
+
records = pickle.load(f)
|
| 91 |
+
records = records.to_dict("records")
|
| 92 |
+
for idx, row in enumerate(records):
|
| 93 |
+
yield idx, {
|
| 94 |
+
"index": idx,
|
| 95 |
+
"hashtag": row["hashtags"],
|
| 96 |
+
"segmentation": get_segmentation(row),
|
| 97 |
+
"alternatives": get_alternatives(row)
|
| 98 |
+
}
|