Initial release
Browse files- README.md +61 -0
- code/aya_ner.py +65 -0
- croguana-500.png +3 -0
- data/train.parquet +3 -0
README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- hr
|
| 4 |
+
license: cc-by-sa-4.0
|
| 5 |
+
pretty_name: Croatian named entities as chats
|
| 6 |
+
size_categories:
|
| 7 |
+
- 1K<n<10K
|
| 8 |
+
task_categories:
|
| 9 |
+
- text-generation
|
| 10 |
+
tags:
|
| 11 |
+
- croatian
|
| 12 |
+
- named-entity-recognition
|
| 13 |
+
- ner
|
| 14 |
+
- instruction-tuning
|
| 15 |
+
configs:
|
| 16 |
+
- config_name: default
|
| 17 |
+
data_files:
|
| 18 |
+
- split: train
|
| 19 |
+
path: data/train.parquet
|
| 20 |
+
---
|
| 21 |
+
|
| 22 |
+
<div align="center">
|
| 23 |
+
<img src="croguana-500.png" width="360">
|
| 24 |
+
</div>
|
| 25 |
+
|
| 26 |
+
# hr-ner-chat — imenovani entiteti kao razgovori
|
| 27 |
+
|
| 28 |
+
Dio zbirke hrvatskih skupova podataka projekta CroGuana / part of the CroGuana Croatian data collection: [hr-arithmetic](https://huggingface.co/datasets/Shome/hr-arithmetic) · [hr-wiki-instruct](https://huggingface.co/datasets/Shome/hr-wiki-instruct) · [hr-bible](https://huggingface.co/datasets/Shome/hr-bible) · [hr-ner-chat](https://huggingface.co/datasets/Shome/hr-ner-chat) · [hy4-croatian-synthetic-v1](https://huggingface.co/datasets/Shome/hy4-croatian-synthetic-v1)
|
| 29 |
+
|
| 30 |
+
## Hrvatski
|
| 31 |
+
|
| 32 |
+
7,870 hrvatskih rečenica iz novinskih tekstova s označenim imenovanim entitetima, prepisanih u kratke razgovore:
|
| 33 |
+
korisnik traži entitete, asistent ih nabraja kao `- Kosovu (lokacija)`.
|
| 34 |
+
|
| 35 |
+
- Izvor: hrvatski dio zbirke Aya (`CohereLabs/aya_collection_language_split`, `croatian/`, podskup UNER-LLM-inst), koji
|
| 36 |
+
potječe iz Universal NER (hr500k). Korištene su podjele train i validation; **testna podjela UNER-a izostavljena je**.
|
| 37 |
+
- Kategorije: osoba (PER), organizacija (ORG), lokacija (LOC) i **ostalo** (OTH: proizvodi, događaji, zakoni, djela,
|
| 38 |
+
nazivi naroda), ukupno 873 odgovora s „ostalo”. Oko 39 % rečenica nema entiteta i dobiva odgovor da ih nema.
|
| 39 |
+
- Uklonjeni su izvorni dugi predlošci uputa (~250 tokena po retku) i znakovni pomaci; upute su pet kratkih hrvatskih
|
| 40 |
+
formulacija. Odbačen 1 redak s neispravnim rasponom i 1 redak koji se preklapa s našim evaluacijskim skupovima.
|
| 41 |
+
- Poznato ograničenje iz izvora: rijetko su spojeni entiteti (npr. ustanova i ime osobe kao jedna „osoba”).
|
| 42 |
+
|
| 43 |
+
## English
|
| 44 |
+
|
| 45 |
+
7,870 Croatian news sentences with named entities, rewritten as short chats (the assistant lists entities as
|
| 46 |
+
`- Kosovu (lokacija)`). From the Croatian part of the Aya collection (UNER-LLM-inst, derived from Universal NER / hr500k);
|
| 47 |
+
train and validation splits only, the UNER test split is left out. Labels: person, organisation, location and *ostalo*
|
| 48 |
+
(other: products, events, laws, works, nationality nouns). About 39% of sentences have no entities. The long original
|
| 49 |
+
prompt template and character offsets were dropped. Known source issue: a few merged entity spans.
|
| 50 |
+
|
| 51 |
+
## Izvori i licence / Sources and licences
|
| 52 |
+
|
| 53 |
+
- Aya collection (Cohere For AI), Apache-2.0; Singh et al., *Aya Dataset: An Open-Access Collection for Multilingual
|
| 54 |
+
Instruction Tuning*, 2024.
|
| 55 |
+
- Universal NER, CC BY-SA 4.0; Mayhew et al., *Universal NER: A Gold-Standard Multilingual Named Entity Recognition
|
| 56 |
+
Benchmark*, NAACL 2024.
|
| 57 |
+
- hr500k; Ljubešić et al., *New Inflectional Lexicons and Training Corpora for Improved Morphosyntactic Annotation of
|
| 58 |
+
Croatian and Serbian*, LREC 2016.
|
| 59 |
+
- Ovaj repozitorij / this repository: CC BY-SA 4.0 (slijedi UNER / follows UNER).
|
| 60 |
+
|
| 61 |
+
Zahtjeve za ispravak ili uklanjanje pošaljite kroz karticu **Community** ovog repozitorija. / Requests for corrections or removal: please use the **Community** tab of this repository.
|
code/aya_ner.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""hr-aya-ner part: Croatian named-entity rows from CohereLabs/aya_collection_language_split, croatian/ (Apache-2.0).
|
| 2 |
+
|
| 3 |
+
The Croatian split is only UNER-LLM-inst: 9,007 rows from one template, made from Universal NER hr500k news
|
| 4 |
+
sentences (PER/ORG/LOC/OTH with character offsets; OTH = other names: products, events, laws, works, nationality nouns; kept as 'ostalo'; 39% of rows have no entities). Train and validation are used and the
|
| 5 |
+
UNER test split is left out. Each row is rewritten as a short chat: one of several Croatian instructions plus the
|
| 6 |
+
sentence, answered with entity lines "- <text> (osoba|organizacija|lokacija|ostalo)" or a no-entities sentence. The 250-token
|
| 7 |
+
boilerplate prompt and JSON offsets are dropped (a 122M model cannot count characters). Screened like build.py.
|
| 8 |
+
|
| 9 |
+
python aya_ner.py (source: sources/aya-hr/croatian/*.parquet)
|
| 10 |
+
"""
|
| 11 |
+
import gzip
|
| 12 |
+
import json
|
| 13 |
+
import random
|
| 14 |
+
import re
|
| 15 |
+
from pathlib import Path
|
| 16 |
+
|
| 17 |
+
import pandas as pd
|
| 18 |
+
|
| 19 |
+
from build import HERE, clean_hit, load_screen, strings
|
| 20 |
+
|
| 21 |
+
SRC = Path('sources/aya-hr/croatian')
|
| 22 |
+
KIND = {'PER': 'osoba', 'ORG': 'organizacija', 'LOC': 'lokacija', 'OTH': 'ostalo'}
|
| 23 |
+
ASK = [
|
| 24 |
+
'Pronađi sve imenovane entitete (osobe, organizacije, lokacije i ostala imena) u rečenici:\n\n{s}',
|
| 25 |
+
'Koje se osobe, organizacije, mjesta i druga imena spominju u ovoj rečenici?\n\n{s}',
|
| 26 |
+
'Izdvoji imenovane entitete iz rečenice i označi jesu li osoba, organizacija, lokacija ili ostalo (proizvodi, događaji, zakoni, djela, narodi).\n\n{s}',
|
| 27 |
+
'Rečenica: {s}\n\nNavedi imena osoba, organizacija, lokacija i ostala imena koja se u njoj pojavljuju.',
|
| 28 |
+
'Prepoznaj imenovane entitete (osoba / organizacija / lokacija / ostalo):\n{s}',
|
| 29 |
+
]
|
| 30 |
+
NONE = ['U rečenici nema imenovanih entiteta.', 'Nema spomenutih osoba, organizacija, lokacija ni drugih imena.',
|
| 31 |
+
'Ova rečenica ne sadrži imenovane entitete.']
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def main():
|
| 35 |
+
rng = random.Random(251125)
|
| 36 |
+
d = pd.concat([pd.read_parquet(SRC / f'{s}-00000-of-00001.parquet') for s in ('train', 'validation')])
|
| 37 |
+
rows, bad = [], 0
|
| 38 |
+
for r in d.itertuples():
|
| 39 |
+
sent = r.inputs.split('koji je konačni izlaz?', 1)[1].strip()
|
| 40 |
+
ents = json.loads('{' + r.targets.strip() + '}')['Results']
|
| 41 |
+
if any(not e.get('Text') or e['Text'] not in sent or e['TypeName'] not in KIND for e in ents):
|
| 42 |
+
bad += 1
|
| 43 |
+
continue
|
| 44 |
+
seen, lines = set(), []
|
| 45 |
+
for e in ents:
|
| 46 |
+
if (e['Text'], e['TypeName']) not in seen:
|
| 47 |
+
seen.add((e['Text'], e['TypeName']))
|
| 48 |
+
lines.append(f"- {e['Text']} ({KIND[e['TypeName']]})")
|
| 49 |
+
rows.append(dict(id=f'aya-ner:{r.id}', messages=[
|
| 50 |
+
dict(role='user', content=rng.choice(ASK).format(s=sent)),
|
| 51 |
+
dict(role='assistant', content='\n'.join(lines) if lines else rng.choice(NONE))]))
|
| 52 |
+
auto, _ = load_screen()
|
| 53 |
+
kept = [r for r in rows if clean_hit(auto, r)]
|
| 54 |
+
with gzip.open(HERE / 'parts/hr-aya-ner.jsonl.gz', 'wt', encoding='utf-8') as f:
|
| 55 |
+
for r in kept:
|
| 56 |
+
f.write(json.dumps(r, ensure_ascii=False) + '\n')
|
| 57 |
+
rep = json.loads((HERE / 'build.json').read_text())
|
| 58 |
+
rep['parts']['hr-aya-ner'] = dict(rows=len(d), bad_spans=bad, kept=len(kept), screened_out=len(rows) - len(kept),
|
| 59 |
+
chars=sum(len(' '.join(strings(r['messages']))) for r in kept))
|
| 60 |
+
(HERE / 'build.json').write_text(json.dumps(rep, indent=1, ensure_ascii=False))
|
| 61 |
+
print(rep['parts']['hr-aya-ner'])
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
if __name__ == '__main__':
|
| 65 |
+
main()
|
croguana-500.png
ADDED
|
Git LFS Details
|
data/train.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c20ceff4dd5235e415c9574d50ec854fb056ea0f023914490199fcf0b8994c93
|
| 3 |
+
size 961034
|