Datasets:
Tasks:
Token Classification
Modalities:
Text
Formats:
json
Sub-tasks:
named-entity-recognition
Languages:
Persian
Size:
10K - 100K
ArXiv:
DOI:
License:
fa-perdt-ner v1: silver + llm (guideline v2.2) configs
Browse files- .gitattributes +1 -0
- LICENSE +465 -0
- README.md +312 -0
- annotation/GUIDELINES.md +166 -0
- annotation/prompt-v2.2.md +47 -0
- annotation/scripts/annotate.js +155 -0
- annotation/scripts/build_requests.py +108 -0
- annotation/scripts/compare_to_silver.py +137 -0
- annotation/scripts/export_iob.py +90 -0
- annotation/scripts/sample_gold.py +138 -0
- annotation/scripts/score_gold.py +213 -0
- annotation/scripts/select_sentences.py +197 -0
- annotation/scripts/validate_responses.py +140 -0
- llm/agreement.json +133 -0
- llm/dev.iob +0 -0
- llm/dev.jsonl +0 -0
- llm/dropped-entities.jsonl +42 -0
- llm/test.iob +0 -0
- llm/test.jsonl +0 -0
- llm/train.iob +0 -0
- llm/train.jsonl +3 -0
- manifest.json +361 -0
- silver/dev.iob +0 -0
- silver/dev.jsonl +0 -0
- silver/test.iob +0 -0
- silver/test.jsonl +0 -0
- silver/train.iob +0 -0
- silver/train.jsonl +0 -0
.gitattributes
CHANGED
|
@@ -58,3 +58,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 58 |
# Video files - compressed
|
| 59 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 60 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 58 |
# Video files - compressed
|
| 59 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 60 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
| 61 |
+
llm/train.jsonl filter=lfs diff=lfs merge=lfs -text
|
LICENSE
ADDED
|
@@ -0,0 +1,465 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fa-perdt-ner is licensed under the Creative Commons Attribution-ShareAlike 4.0
|
| 2 |
+
International licence (CC BY-SA 4.0). The full legal code follows the notice.
|
| 3 |
+
|
| 4 |
+
ATTRIBUTION NOTICE
|
| 5 |
+
|
| 6 |
+
Both configurations of this dataset are Adapted Material derived from the Persian
|
| 7 |
+
Universal Dependency Treebank (UD_Persian-PerDT, PerUDT v1.0), licensed CC BY-SA 4.0:
|
| 8 |
+
|
| 9 |
+
Source: https://github.com/UniversalDependencies/UD_Persian-PerDT
|
| 10 |
+
Licence: https://creativecommons.org/licenses/by-sa/4.0/
|
| 11 |
+
Authors: Mohammad Sadegh Rasooli, Pegah Safari, Amirsaeid Moloodi, Alireza Nourian
|
| 12 |
+
Cite: Rasooli, Safari, Moloodi, Nourian. "The Persian Dependency Treebank Made
|
| 13 |
+
Universal." LREC 2022. https://aclanthology.org/2022.lrec-1.766
|
| 14 |
+
(preprint arXiv:2009.10205)
|
| 15 |
+
Rasooli, Kouhestani, Moloodi. "Development of a Persian syntactic dependency
|
| 16 |
+
treebank." NAACL-HLT 2013. https://aclanthology.org/N13-1031
|
| 17 |
+
|
| 18 |
+
The sentence text and tokenization in every split are PerDT's. The `silver` configuration is
|
| 19 |
+
PerDT's own named-entity layer (not-to-release/Dadegan with NER tag/, produced with the
|
| 20 |
+
Beheshti-NER tagger of Taher, Hoseini and Shamsfard 2020, arXiv:2003.08875, plus manual
|
| 21 |
+
corrections by the PerDT authors), realigned onto the Universal Dependencies tokenization.
|
| 22 |
+
The `llm` configuration is a new annotation of the same sentences produced by a large
|
| 23 |
+
language model against a written guideline; the guideline was inferred from the `silver`
|
| 24 |
+
layer, so it too derives from PerDT.
|
| 25 |
+
|
| 26 |
+
Modifications made to the licensed material: multiword tokens merged into their surface
|
| 27 |
+
form (`spacy convert --merge-subtokens`); entity spans realigned onto that tokenization by
|
| 28 |
+
difflib, with spans that could not be aligned exactly dropped rather than guessed (`silver`);
|
| 29 |
+
sentences relabelled with four entity types under annotation/GUIDELINES.md (`llm`). Details
|
| 30 |
+
and counts are in README.md and manifest.json.
|
| 31 |
+
|
| 32 |
+
The dataset is provided as-is, without warranties of any kind, and the licensor disclaims
|
| 33 |
+
liability for damages arising from its use, to the extent permitted by CC BY-SA 4.0
|
| 34 |
+
sections 5(a) and 5(b).
|
| 35 |
+
|
| 36 |
+
=======================================================================
|
| 37 |
+
|
| 38 |
+
Attribution-ShareAlike 4.0 International
|
| 39 |
+
|
| 40 |
+
=======================================================================
|
| 41 |
+
|
| 42 |
+
Creative Commons Corporation ("Creative Commons") is not a law firm and
|
| 43 |
+
does not provide legal services or legal advice. Distribution of
|
| 44 |
+
Creative Commons public licenses does not create a lawyer-client or
|
| 45 |
+
other relationship. Creative Commons makes its licenses and related
|
| 46 |
+
information available on an "as-is" basis. Creative Commons gives no
|
| 47 |
+
warranties regarding its licenses, any material licensed under their
|
| 48 |
+
terms and conditions, or any related information. Creative Commons
|
| 49 |
+
disclaims all liability for damages resulting from their use to the
|
| 50 |
+
fullest extent possible.
|
| 51 |
+
|
| 52 |
+
Using Creative Commons Public Licenses
|
| 53 |
+
|
| 54 |
+
Creative Commons public licenses provide a standard set of terms and
|
| 55 |
+
conditions that creators and other rights holders may use to share
|
| 56 |
+
original works of authorship and other material subject to copyright
|
| 57 |
+
and certain other rights specified in the public license below. The
|
| 58 |
+
following considerations are for informational purposes only, are not
|
| 59 |
+
exhaustive, and do not form part of our licenses.
|
| 60 |
+
|
| 61 |
+
Considerations for licensors: Our public licenses are
|
| 62 |
+
intended for use by those authorized to give the public
|
| 63 |
+
permission to use material in ways otherwise restricted by
|
| 64 |
+
copyright and certain other rights. Our licenses are
|
| 65 |
+
irrevocable. Licensors should read and understand the terms
|
| 66 |
+
and conditions of the license they choose before applying it.
|
| 67 |
+
Licensors should also secure all rights necessary before
|
| 68 |
+
applying our licenses so that the public can reuse the
|
| 69 |
+
material as expected. Licensors should clearly mark any
|
| 70 |
+
material not subject to the license. This includes other CC-
|
| 71 |
+
licensed material, or material used under an exception or
|
| 72 |
+
limitation to copyright. More considerations for licensors:
|
| 73 |
+
wiki.creativecommons.org/Considerations_for_licensors
|
| 74 |
+
|
| 75 |
+
Considerations for the public: By using one of our public
|
| 76 |
+
licenses, a licensor grants the public permission to use the
|
| 77 |
+
licensed material under specified terms and conditions. If
|
| 78 |
+
the licensor's permission is not necessary for any reason--for
|
| 79 |
+
example, because of any applicable exception or limitation to
|
| 80 |
+
copyright--then that use is not regulated by the license. Our
|
| 81 |
+
licenses grant only permissions under copyright and certain
|
| 82 |
+
other rights that a licensor has authority to grant. Use of
|
| 83 |
+
the licensed material may still be restricted for other
|
| 84 |
+
reasons, including because others have copyright or other
|
| 85 |
+
rights in the material. A licensor may make special requests,
|
| 86 |
+
such as asking that all changes be marked or described.
|
| 87 |
+
Although not required by our licenses, you are encouraged to
|
| 88 |
+
respect those requests where reasonable. More considerations
|
| 89 |
+
for the public:
|
| 90 |
+
wiki.creativecommons.org/Considerations_for_licensees
|
| 91 |
+
|
| 92 |
+
=======================================================================
|
| 93 |
+
|
| 94 |
+
Creative Commons Attribution-ShareAlike 4.0 International Public
|
| 95 |
+
License
|
| 96 |
+
|
| 97 |
+
By exercising the Licensed Rights (defined below), You accept and agree
|
| 98 |
+
to be bound by the terms and conditions of this Creative Commons
|
| 99 |
+
Attribution-ShareAlike 4.0 International Public License ("Public
|
| 100 |
+
License"). To the extent this Public License may be interpreted as a
|
| 101 |
+
contract, You are granted the Licensed Rights in consideration of Your
|
| 102 |
+
acceptance of these terms and conditions, and the Licensor grants You
|
| 103 |
+
such rights in consideration of benefits the Licensor receives from
|
| 104 |
+
making the Licensed Material available under these terms and
|
| 105 |
+
conditions.
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
Section 1 -- Definitions.
|
| 109 |
+
|
| 110 |
+
a. Adapted Material means material subject to Copyright and Similar
|
| 111 |
+
Rights that is derived from or based upon the Licensed Material
|
| 112 |
+
and in which the Licensed Material is translated, altered,
|
| 113 |
+
arranged, transformed, or otherwise modified in a manner requiring
|
| 114 |
+
permission under the Copyright and Similar Rights held by the
|
| 115 |
+
Licensor. For purposes of this Public License, where the Licensed
|
| 116 |
+
Material is a musical work, performance, or sound recording,
|
| 117 |
+
Adapted Material is always produced where the Licensed Material is
|
| 118 |
+
synched in timed relation with a moving image.
|
| 119 |
+
|
| 120 |
+
b. Adapter's License means the license You apply to Your Copyright
|
| 121 |
+
and Similar Rights in Your contributions to Adapted Material in
|
| 122 |
+
accordance with the terms and conditions of this Public License.
|
| 123 |
+
|
| 124 |
+
c. BY-SA Compatible License means a license listed at
|
| 125 |
+
creativecommons.org/compatiblelicenses, approved by Creative
|
| 126 |
+
Commons as essentially the equivalent of this Public License.
|
| 127 |
+
|
| 128 |
+
d. Copyright and Similar Rights means copyright and/or similar rights
|
| 129 |
+
closely related to copyright including, without limitation,
|
| 130 |
+
performance, broadcast, sound recording, and Sui Generis Database
|
| 131 |
+
Rights, without regard to how the rights are labeled or
|
| 132 |
+
categorized. For purposes of this Public License, the rights
|
| 133 |
+
specified in Section 2(b)(1)-(2) are not Copyright and Similar
|
| 134 |
+
Rights.
|
| 135 |
+
|
| 136 |
+
e. Effective Technological Measures means those measures that, in the
|
| 137 |
+
absence of proper authority, may not be circumvented under laws
|
| 138 |
+
fulfilling obligations under Article 11 of the WIPO Copyright
|
| 139 |
+
Treaty adopted on December 20, 1996, and/or similar international
|
| 140 |
+
agreements.
|
| 141 |
+
|
| 142 |
+
f. Exceptions and Limitations means fair use, fair dealing, and/or
|
| 143 |
+
any other exception or limitation to Copyright and Similar Rights
|
| 144 |
+
that applies to Your use of the Licensed Material.
|
| 145 |
+
|
| 146 |
+
g. License Elements means the license attributes listed in the name
|
| 147 |
+
of a Creative Commons Public License. The License Elements of this
|
| 148 |
+
Public License are Attribution and ShareAlike.
|
| 149 |
+
|
| 150 |
+
h. Licensed Material means the artistic or literary work, database,
|
| 151 |
+
or other material to which the Licensor applied this Public
|
| 152 |
+
License.
|
| 153 |
+
|
| 154 |
+
i. Licensed Rights means the rights granted to You subject to the
|
| 155 |
+
terms and conditions of this Public License, which are limited to
|
| 156 |
+
all Copyright and Similar Rights that apply to Your use of the
|
| 157 |
+
Licensed Material and that the Licensor has authority to license.
|
| 158 |
+
|
| 159 |
+
j. Licensor means the individual(s) or entity(ies) granting rights
|
| 160 |
+
under this Public License.
|
| 161 |
+
|
| 162 |
+
k. Share means to provide material to the public by any means or
|
| 163 |
+
process that requires permission under the Licensed Rights, such
|
| 164 |
+
as reproduction, public display, public performance, distribution,
|
| 165 |
+
dissemination, communication, or importation, and to make material
|
| 166 |
+
available to the public including in ways that members of the
|
| 167 |
+
public may access the material from a place and at a time
|
| 168 |
+
individually chosen by them.
|
| 169 |
+
|
| 170 |
+
l. Sui Generis Database Rights means rights other than copyright
|
| 171 |
+
resulting from Directive 96/9/EC of the European Parliament and of
|
| 172 |
+
the Council of 11 March 1996 on the legal protection of databases,
|
| 173 |
+
as amended and/or succeeded, as well as other essentially
|
| 174 |
+
equivalent rights anywhere in the world.
|
| 175 |
+
|
| 176 |
+
m. You means the individual or entity exercising the Licensed Rights
|
| 177 |
+
under this Public License. Your has a corresponding meaning.
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
Section 2 -- Scope.
|
| 181 |
+
|
| 182 |
+
a. License grant.
|
| 183 |
+
|
| 184 |
+
1. Subject to the terms and conditions of this Public License,
|
| 185 |
+
the Licensor hereby grants You a worldwide, royalty-free,
|
| 186 |
+
non-sublicensable, non-exclusive, irrevocable license to
|
| 187 |
+
exercise the Licensed Rights in the Licensed Material to:
|
| 188 |
+
|
| 189 |
+
a. reproduce and Share the Licensed Material, in whole or
|
| 190 |
+
in part; and
|
| 191 |
+
|
| 192 |
+
b. produce, reproduce, and Share Adapted Material.
|
| 193 |
+
|
| 194 |
+
2. Exceptions and Limitations. For the avoidance of doubt, where
|
| 195 |
+
Exceptions and Limitations apply to Your use, this Public
|
| 196 |
+
License does not apply, and You do not need to comply with
|
| 197 |
+
its terms and conditions.
|
| 198 |
+
|
| 199 |
+
3. Term. The term of this Public License is specified in Section
|
| 200 |
+
6(a).
|
| 201 |
+
|
| 202 |
+
4. Media and formats; technical modifications allowed. The
|
| 203 |
+
Licensor authorizes You to exercise the Licensed Rights in
|
| 204 |
+
all media and formats whether now known or hereafter created,
|
| 205 |
+
and to make technical modifications necessary to do so. The
|
| 206 |
+
Licensor waives and/or agrees not to assert any right or
|
| 207 |
+
authority to forbid You from making technical modifications
|
| 208 |
+
necessary to exercise the Licensed Rights, including
|
| 209 |
+
technical modifications necessary to circumvent Effective
|
| 210 |
+
Technological Measures. For purposes of this Public License,
|
| 211 |
+
simply making modifications authorized by this Section 2(a)
|
| 212 |
+
(4) never produces Adapted Material.
|
| 213 |
+
|
| 214 |
+
5. Downstream recipients.
|
| 215 |
+
|
| 216 |
+
a. Offer from the Licensor -- Licensed Material. Every
|
| 217 |
+
recipient of the Licensed Material automatically
|
| 218 |
+
receives an offer from the Licensor to exercise the
|
| 219 |
+
Licensed Rights under the terms and conditions of this
|
| 220 |
+
Public License.
|
| 221 |
+
|
| 222 |
+
b. Additional offer from the Licensor -- Adapted Material.
|
| 223 |
+
Every recipient of Adapted Material from You
|
| 224 |
+
automatically receives an offer from the Licensor to
|
| 225 |
+
exercise the Licensed Rights in the Adapted Material
|
| 226 |
+
under the conditions of the Adapter's License You apply.
|
| 227 |
+
|
| 228 |
+
c. No downstream restrictions. You may not offer or impose
|
| 229 |
+
any additional or different terms or conditions on, or
|
| 230 |
+
apply any Effective Technological Measures to, the
|
| 231 |
+
Licensed Material if doing so restricts exercise of the
|
| 232 |
+
Licensed Rights by any recipient of the Licensed
|
| 233 |
+
Material.
|
| 234 |
+
|
| 235 |
+
6. No endorsement. Nothing in this Public License constitutes or
|
| 236 |
+
may be construed as permission to assert or imply that You
|
| 237 |
+
are, or that Your use of the Licensed Material is, connected
|
| 238 |
+
with, or sponsored, endorsed, or granted official status by,
|
| 239 |
+
the Licensor or others designated to receive attribution as
|
| 240 |
+
provided in Section 3(a)(1)(A)(i).
|
| 241 |
+
|
| 242 |
+
b. Other rights.
|
| 243 |
+
|
| 244 |
+
1. Moral rights, such as the right of integrity, are not
|
| 245 |
+
licensed under this Public License, nor are publicity,
|
| 246 |
+
privacy, and/or other similar personality rights; however, to
|
| 247 |
+
the extent possible, the Licensor waives and/or agrees not to
|
| 248 |
+
assert any such rights held by the Licensor to the limited
|
| 249 |
+
extent necessary to allow You to exercise the Licensed
|
| 250 |
+
Rights, but not otherwise.
|
| 251 |
+
|
| 252 |
+
2. Patent and trademark rights are not licensed under this
|
| 253 |
+
Public License.
|
| 254 |
+
|
| 255 |
+
3. To the extent possible, the Licensor waives any right to
|
| 256 |
+
collect royalties from You for the exercise of the Licensed
|
| 257 |
+
Rights, whether directly or through a collecting society
|
| 258 |
+
under any voluntary or waivable statutory or compulsory
|
| 259 |
+
licensing scheme. In all other cases the Licensor expressly
|
| 260 |
+
reserves any right to collect such royalties.
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
Section 3 -- License Conditions.
|
| 264 |
+
|
| 265 |
+
Your exercise of the Licensed Rights is expressly made subject to the
|
| 266 |
+
following conditions.
|
| 267 |
+
|
| 268 |
+
a. Attribution.
|
| 269 |
+
|
| 270 |
+
1. If You Share the Licensed Material (including in modified
|
| 271 |
+
form), You must:
|
| 272 |
+
|
| 273 |
+
a. retain the following if it is supplied by the Licensor
|
| 274 |
+
with the Licensed Material:
|
| 275 |
+
|
| 276 |
+
i. identification of the creator(s) of the Licensed
|
| 277 |
+
Material and any others designated to receive
|
| 278 |
+
attribution, in any reasonable manner requested by
|
| 279 |
+
the Licensor (including by pseudonym if
|
| 280 |
+
designated);
|
| 281 |
+
|
| 282 |
+
ii. a copyright notice;
|
| 283 |
+
|
| 284 |
+
iii. a notice that refers to this Public License;
|
| 285 |
+
|
| 286 |
+
iv. a notice that refers to the disclaimer of
|
| 287 |
+
warranties;
|
| 288 |
+
|
| 289 |
+
v. a URI or hyperlink to the Licensed Material to the
|
| 290 |
+
extent reasonably practicable;
|
| 291 |
+
|
| 292 |
+
b. indicate if You modified the Licensed Material and
|
| 293 |
+
retain an indication of any previous modifications; and
|
| 294 |
+
|
| 295 |
+
c. indicate the Licensed Material is licensed under this
|
| 296 |
+
Public License, and include the text of, or the URI or
|
| 297 |
+
hyperlink to, this Public License.
|
| 298 |
+
|
| 299 |
+
2. You may satisfy the conditions in Section 3(a)(1) in any
|
| 300 |
+
reasonable manner based on the medium, means, and context in
|
| 301 |
+
which You Share the Licensed Material. For example, it may be
|
| 302 |
+
reasonable to satisfy the conditions by providing a URI or
|
| 303 |
+
hyperlink to a resource that includes the required
|
| 304 |
+
information.
|
| 305 |
+
|
| 306 |
+
3. If requested by the Licensor, You must remove any of the
|
| 307 |
+
information required by Section 3(a)(1)(A) to the extent
|
| 308 |
+
reasonably practicable.
|
| 309 |
+
|
| 310 |
+
b. ShareAlike.
|
| 311 |
+
|
| 312 |
+
In addition to the conditions in Section 3(a), if You Share
|
| 313 |
+
Adapted Material You produce, the following conditions also apply.
|
| 314 |
+
|
| 315 |
+
1. The Adapter's License You apply must be a Creative Commons
|
| 316 |
+
license with the same License Elements, this version or
|
| 317 |
+
later, or a BY-SA Compatible License.
|
| 318 |
+
|
| 319 |
+
2. You must include the text of, or the URI or hyperlink to, the
|
| 320 |
+
Adapter's License You apply. You may satisfy this condition
|
| 321 |
+
in any reasonable manner based on the medium, means, and
|
| 322 |
+
context in which You Share Adapted Material.
|
| 323 |
+
|
| 324 |
+
3. You may not offer or impose any additional or different terms
|
| 325 |
+
or conditions on, or apply any Effective Technological
|
| 326 |
+
Measures to, Adapted Material that restrict exercise of the
|
| 327 |
+
rights granted under the Adapter's License You apply.
|
| 328 |
+
|
| 329 |
+
|
| 330 |
+
Section 4 -- Sui Generis Database Rights.
|
| 331 |
+
|
| 332 |
+
Where the Licensed Rights include Sui Generis Database Rights that
|
| 333 |
+
apply to Your use of the Licensed Material:
|
| 334 |
+
|
| 335 |
+
a. for the avoidance of doubt, Section 2(a)(1) grants You the right
|
| 336 |
+
to extract, reuse, reproduce, and Share all or a substantial
|
| 337 |
+
portion of the contents of the database;
|
| 338 |
+
|
| 339 |
+
b. if You include all or a substantial portion of the database
|
| 340 |
+
contents in a database in which You have Sui Generis Database
|
| 341 |
+
Rights, then the database in which You have Sui Generis Database
|
| 342 |
+
Rights (but not its individual contents) is Adapted Material,
|
| 343 |
+
including for purposes of Section 3(b); and
|
| 344 |
+
|
| 345 |
+
c. You must comply with the conditions in Section 3(a) if You Share
|
| 346 |
+
all or a substantial portion of the contents of the database.
|
| 347 |
+
|
| 348 |
+
For the avoidance of doubt, this Section 4 supplements and does not
|
| 349 |
+
replace Your obligations under this Public License where the Licensed
|
| 350 |
+
Rights include other Copyright and Similar Rights.
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
Section 5 -- Disclaimer of Warranties and Limitation of Liability.
|
| 354 |
+
|
| 355 |
+
a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
|
| 356 |
+
EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
|
| 357 |
+
AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
|
| 358 |
+
ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
|
| 359 |
+
IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
|
| 360 |
+
WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
| 361 |
+
PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
|
| 362 |
+
ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
|
| 363 |
+
KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
|
| 364 |
+
ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
|
| 365 |
+
|
| 366 |
+
b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
|
| 367 |
+
TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
|
| 368 |
+
NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
|
| 369 |
+
INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
|
| 370 |
+
COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
|
| 371 |
+
USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
|
| 372 |
+
ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
|
| 373 |
+
DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
|
| 374 |
+
IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
|
| 375 |
+
|
| 376 |
+
c. The disclaimer of warranties and limitation of liability provided
|
| 377 |
+
above shall be interpreted in a manner that, to the extent
|
| 378 |
+
possible, most closely approximates an absolute disclaimer and
|
| 379 |
+
waiver of all liability.
|
| 380 |
+
|
| 381 |
+
|
| 382 |
+
Section 6 -- Term and Termination.
|
| 383 |
+
|
| 384 |
+
a. This Public License applies for the term of the Copyright and
|
| 385 |
+
Similar Rights licensed here. However, if You fail to comply with
|
| 386 |
+
this Public License, then Your rights under this Public License
|
| 387 |
+
terminate automatically.
|
| 388 |
+
|
| 389 |
+
b. Where Your right to use the Licensed Material has terminated under
|
| 390 |
+
Section 6(a), it reinstates:
|
| 391 |
+
|
| 392 |
+
1. automatically as of the date the violation is cured, provided
|
| 393 |
+
it is cured within 30 days of Your discovery of the
|
| 394 |
+
violation; or
|
| 395 |
+
|
| 396 |
+
2. upon express reinstatement by the Licensor.
|
| 397 |
+
|
| 398 |
+
For the avoidance of doubt, this Section 6(b) does not affect any
|
| 399 |
+
right the Licensor may have to seek remedies for Your violations
|
| 400 |
+
of this Public License.
|
| 401 |
+
|
| 402 |
+
c. For the avoidance of doubt, the Licensor may also offer the
|
| 403 |
+
Licensed Material under separate terms or conditions or stop
|
| 404 |
+
distributing the Licensed Material at any time; however, doing so
|
| 405 |
+
will not terminate this Public License.
|
| 406 |
+
|
| 407 |
+
d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
|
| 408 |
+
License.
|
| 409 |
+
|
| 410 |
+
|
| 411 |
+
Section 7 -- Other Terms and Conditions.
|
| 412 |
+
|
| 413 |
+
a. The Licensor shall not be bound by any additional or different
|
| 414 |
+
terms or conditions communicated by You unless expressly agreed.
|
| 415 |
+
|
| 416 |
+
b. Any arrangements, understandings, or agreements regarding the
|
| 417 |
+
Licensed Material not stated herein are separate from and
|
| 418 |
+
independent of the terms and conditions of this Public License.
|
| 419 |
+
|
| 420 |
+
|
| 421 |
+
Section 8 -- Interpretation.
|
| 422 |
+
|
| 423 |
+
a. For the avoidance of doubt, this Public License does not, and
|
| 424 |
+
shall not be interpreted to, reduce, limit, restrict, or impose
|
| 425 |
+
conditions on any use of the Licensed Material that could lawfully
|
| 426 |
+
be made without permission under this Public License.
|
| 427 |
+
|
| 428 |
+
b. To the extent possible, if any provision of this Public License is
|
| 429 |
+
deemed unenforceable, it shall be automatically reformed to the
|
| 430 |
+
minimum extent necessary to make it enforceable. If the provision
|
| 431 |
+
cannot be reformed, it shall be severed from this Public License
|
| 432 |
+
without affecting the enforceability of the remaining terms and
|
| 433 |
+
conditions.
|
| 434 |
+
|
| 435 |
+
c. No term or condition of this Public License will be waived and no
|
| 436 |
+
failure to comply consented to unless expressly agreed to by the
|
| 437 |
+
Licensor.
|
| 438 |
+
|
| 439 |
+
d. Nothing in this Public License constitutes or may be interpreted
|
| 440 |
+
as a limitation upon, or waiver of, any privileges and immunities
|
| 441 |
+
that apply to the Licensor or You, including from the legal
|
| 442 |
+
processes of any jurisdiction or authority.
|
| 443 |
+
|
| 444 |
+
|
| 445 |
+
=======================================================================
|
| 446 |
+
|
| 447 |
+
Creative Commons is not a party to its public
|
| 448 |
+
licenses. Notwithstanding, Creative Commons may elect to apply one of
|
| 449 |
+
its public licenses to material it publishes and in those instances
|
| 450 |
+
will be considered the “Licensor.” The text of the Creative Commons
|
| 451 |
+
public licenses is dedicated to the public domain under the CC0 Public
|
| 452 |
+
Domain Dedication. Except for the limited purpose of indicating that
|
| 453 |
+
material is shared under a Creative Commons public license or as
|
| 454 |
+
otherwise permitted by the Creative Commons policies published at
|
| 455 |
+
creativecommons.org/policies, Creative Commons does not authorize the
|
| 456 |
+
use of the trademark "Creative Commons" or any other trademark or logo
|
| 457 |
+
of Creative Commons without its prior written consent including,
|
| 458 |
+
without limitation, in connection with any unauthorized modifications
|
| 459 |
+
to any of its public licenses or any other arrangements,
|
| 460 |
+
understandings, or agreements concerning use of licensed material. For
|
| 461 |
+
the avoidance of doubt, this paragraph does not form part of the
|
| 462 |
+
public licenses.
|
| 463 |
+
|
| 464 |
+
Creative Commons may be contacted at creativecommons.org.
|
| 465 |
+
|
README.md
ADDED
|
@@ -0,0 +1,312 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- fa
|
| 4 |
+
license: cc-by-sa-4.0
|
| 5 |
+
license_name: cc-by-sa-4.0
|
| 6 |
+
license_link: LICENSE
|
| 7 |
+
pretty_name: "fa-perdt-ner: Persian NER over the PerDT treebank, silver and LLM-relabelled"
|
| 8 |
+
task_categories:
|
| 9 |
+
- token-classification
|
| 10 |
+
task_ids:
|
| 11 |
+
- named-entity-recognition
|
| 12 |
+
annotations_creators:
|
| 13 |
+
- machine-generated
|
| 14 |
+
- expert-generated
|
| 15 |
+
language_creators:
|
| 16 |
+
- found
|
| 17 |
+
multilinguality:
|
| 18 |
+
- monolingual
|
| 19 |
+
size_categories:
|
| 20 |
+
- 10K<n<100K
|
| 21 |
+
source_datasets:
|
| 22 |
+
- extended|universal_dependencies
|
| 23 |
+
tags:
|
| 24 |
+
- persian
|
| 25 |
+
- farsi
|
| 26 |
+
- ner
|
| 27 |
+
- named-entity-recognition
|
| 28 |
+
- universal-dependencies
|
| 29 |
+
- perdt
|
| 30 |
+
- spacy
|
| 31 |
+
- llm-annotated
|
| 32 |
+
configs:
|
| 33 |
+
- config_name: silver
|
| 34 |
+
default: true
|
| 35 |
+
data_files:
|
| 36 |
+
- split: train
|
| 37 |
+
path: silver/train.jsonl
|
| 38 |
+
- split: validation
|
| 39 |
+
path: silver/dev.jsonl
|
| 40 |
+
- split: test
|
| 41 |
+
path: silver/test.jsonl
|
| 42 |
+
- config_name: llm
|
| 43 |
+
data_files:
|
| 44 |
+
- split: train
|
| 45 |
+
path: llm/train.jsonl
|
| 46 |
+
- split: validation
|
| 47 |
+
path: llm/dev.jsonl
|
| 48 |
+
- split: test
|
| 49 |
+
path: llm/test.jsonl
|
| 50 |
+
---
|
| 51 |
+
|
| 52 |
+
# fa-perdt-ner
|
| 53 |
+
|
| 54 |
+
Persian named-entity annotations over every sentence of the Persian Universal Dependency
|
| 55 |
+
Treebank ([UD_Persian-PerDT](https://github.com/UniversalDependencies/UD_Persian-PerDT),
|
| 56 |
+
PerUDT v1.0): 29,107 sentences, 494,163 tokens, in PerDT's own train/dev/test
|
| 57 |
+
split, on the tokenization a spaCy `--merge-subtokens` conversion of the treebank produces.
|
| 58 |
+
|
| 59 |
+
Two configurations, same sentences, same tokens, different labels:
|
| 60 |
+
|
| 61 |
+
| config | labels | entities | what it is |
|
| 62 |
+
|---|---|---|---|
|
| 63 |
+
| `silver` (default) | `PER LOC ORG DAT MON TIM PCT` | 15,807 | PerDT's own NER layer, realigned onto the UD tokenization. Produced by the PerDT authors with the Beheshti-NER tagger plus manual corrections; **silver, not gold**. |
|
| 64 |
+
| `llm` | `PER LOC ORG DAT` | 15,144 | A fresh annotation of the same sentences by a large language model, against a written guideline (v2.2) inferred from the silver layer. Four labels only. |
|
| 65 |
+
|
| 66 |
+
**Read this before comparing anything.** `llm` has four labels; `silver` has seven. A model
|
| 67 |
+
trained on one and scored on the other must be restricted to the four shared types, or every
|
| 68 |
+
correct `MON`/`TIM`/`PCT` span becomes a false positive. And neither configuration is human
|
| 69 |
+
gold: every agreement figure on this card is agreement between two annotators, not accuracy.
|
| 70 |
+
|
| 71 |
+
The text and split are PerDT's, CC BY-SA 4.0; this dataset is Adapted Material under the same
|
| 72 |
+
licence. See [Licence and attribution](#licence-and-attribution).
|
| 73 |
+
|
| 74 |
+
## Loading
|
| 75 |
+
|
| 76 |
+
```python
|
| 77 |
+
from datasets import load_dataset
|
| 78 |
+
|
| 79 |
+
silver = load_dataset("Phazel/fa-perdt-ner", "silver") # 7 labels
|
| 80 |
+
llm = load_dataset("Phazel/fa-perdt-ner", "llm") # 4 labels
|
| 81 |
+
|
| 82 |
+
row = llm["test"][0]
|
| 83 |
+
row["id"] # PerDT sent_id, e.g. "test-s1"
|
| 84 |
+
row["tokens"] # ["این", "موافقتنامه", "را", ...]
|
| 85 |
+
row["ner_tags"] # ["O", "O", "O", ...] IOB2 strings, parallel to tokens
|
| 86 |
+
row["entities"] # [{"start": 3, "end": 5, "label": "ORG"}, ...] token offsets, end exclusive
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
Splits are named `train`, `validation` (PerDT `dev`) and `test`. `ner_tags` are IOB2 strings,
|
| 90 |
+
not a `ClassLabel`, so the two configurations can share one loader; map them yourself if a
|
| 91 |
+
trainer wants integers.
|
| 92 |
+
|
| 93 |
+
Both configurations also ship as two-column IOB2 (`<config>/{train,dev,test}.iob`, tab
|
| 94 |
+
separated, blank line between sentences), which `spacy convert` reads directly:
|
| 95 |
+
|
| 96 |
+
```bash
|
| 97 |
+
python -m spacy convert llm/train.iob corpus/ --converter ner --lang fa
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
The tokenization is exactly what `spacy convert --merge-subtokens` yields from the PerDT
|
| 101 |
+
CoNLL-U files, so these files can be paired with a parser or tagger trained on the treebank
|
| 102 |
+
without re-alignment. That is how the
|
| 103 |
+
[`fa_core_news_*`](https://huggingface.co/Phazel/fa_core_news_sm) pipelines were built.
|
| 104 |
+
|
| 105 |
+
## Fields
|
| 106 |
+
|
| 107 |
+
`silver/*.jsonl`:
|
| 108 |
+
|
| 109 |
+
| field | type | |
|
| 110 |
+
|---|---|---|
|
| 111 |
+
| `id` | string | PerDT `sent_id` (`train-s1`, `dev-s12`, ...) |
|
| 112 |
+
| `tokens` | list[string] | merged-subtoken surface forms, in order |
|
| 113 |
+
| `ner_tags` | list[string] | IOB2 tag per token |
|
| 114 |
+
|
| 115 |
+
`llm/*.jsonl` adds:
|
| 116 |
+
|
| 117 |
+
| field | type | |
|
| 118 |
+
|---|---|---|
|
| 119 |
+
| `entities` | list[{start, end, label}] | token offsets, `end` exclusive; the spans `ner_tags` encodes |
|
| 120 |
+
| `prompt_hash` | string | `3c5f435761a2` for every row: hash of the guideline+prompt that produced it |
|
| 121 |
+
| `error` | string or null | `"missing"` on the 1 sentence(s) the model refused to annotate: `train-s16861` |
|
| 122 |
+
|
| 123 |
+
## Statistics
|
| 124 |
+
|
| 125 |
+
`silver`:
|
| 126 |
+
|
| 127 |
+
| split | sentences | tokens | entities | PER | LOC | ORG | DAT | MON | TIM | PCT |
|
| 128 |
+
|---|---|---|---|---|---|---|---|---|---|---|
|
| 129 |
+
| train | 26196 | 445587 | 14228 | 4847 | 4954 | 2643 | 1323 | 205 | 135 | 121 |
|
| 130 |
+
| dev | 1456 | 24751 | 773 | 255 | 260 | 151 | 79 | 11 | 8 | 9 |
|
| 131 |
+
| test | 1455 | 23825 | 806 | 297 | 273 | 144 | 69 | 10 | 9 | 4 |
|
| 132 |
+
|
| 133 |
+
`llm`:
|
| 134 |
+
|
| 135 |
+
| split | sentences | tokens | entities | PER | LOC | ORG | DAT |
|
| 136 |
+
|---|---|---|---|---|---|---|---|
|
| 137 |
+
| train | 26196 | 445587 | 13644 | 4771 | 5011 | 2278 | 1584 |
|
| 138 |
+
| dev | 1456 | 24751 | 731 | 251 | 258 | 135 | 87 |
|
| 139 |
+
| test | 1455 | 23825 | 769 | 281 | 271 | 133 | 84 |
|
| 140 |
+
|
| 141 |
+
Entity counts are spans, from the IOB2 tags. Token counts are the same in both configurations
|
| 142 |
+
by construction.
|
| 143 |
+
|
| 144 |
+
## Provenance
|
| 145 |
+
|
| 146 |
+
### Text and split
|
| 147 |
+
|
| 148 |
+
PerDT ([Rasooli et al. 2013](https://aclanthology.org/N13-1031)) is ~29k sentences of
|
| 149 |
+
contemporary Persian across news, academic, magazine and fiction genres. Its UD conversion
|
| 150 |
+
([Rasooli et al. 2022](https://aclanthology.org/2022.lrec-1.766)) is what was downloaded, at
|
| 151 |
+
the URLs and MD5 checksums recorded in `manifest.json`. The 89/5/5 split is PerDT's own; no
|
| 152 |
+
sentence was moved, dropped or deduplicated.
|
| 153 |
+
|
| 154 |
+
Tokenization: the CoNLL-U multiword tokens (pronominal clitics, enclitic copula) are merged
|
| 155 |
+
back into their surface form, i.e. `spacy convert --merge-subtokens`. `پدرم` is one token,
|
| 156 |
+
not `پدر` + `م`. This is the tokenization a spaCy `fa` tokenizer can actually produce, and the
|
| 157 |
+
one every `Phazel/fa_*` pipeline is trained on.
|
| 158 |
+
|
| 159 |
+
### `silver`
|
| 160 |
+
|
| 161 |
+
PerDT ships an entity layer at `not-to-release/Dadegan with NER tag/`, two-column IOB2 on
|
| 162 |
+
the *original* Dadegan tokenization, which matches the released UD tokenization in only
|
| 163 |
+
57-62% of sentences (the NER files drop some copulas and auxiliaries). The PerDT README
|
| 164 |
+
states this layer was produced with the BERT-based Beheshti-NER tagger
|
| 165 |
+
([Taher, Hoseini & Shamsfard 2020](https://arxiv.org/abs/2003.08875)) "with manual
|
| 166 |
+
corrections to extend recall", and was used to mark `PROPN` in the treebank.
|
| 167 |
+
|
| 168 |
+
`scripts/transfer_perdt_ner.py` (in the
|
| 169 |
+
[pipeline repo](https://github.com/Fazel94/spacy-persian)) aligns each sentence's two token
|
| 170 |
+
sequences with `difflib` and moves a span only if every one of its tokens maps and the result
|
| 171 |
+
stays contiguous. Anything else is dropped rather than guessed. Transfer rate: 99.86% of
|
| 172 |
+
spans on train, 99.74% on dev, 99.51% on test.
|
| 173 |
+
|
| 174 |
+
Known artefacts inherited from that layer, left as they are: the opening `(` of a
|
| 175 |
+
parenthetical blessing formula is tagged `I-PER` a few hundred times; a handful of entities
|
| 176 |
+
carry inconsistent boundaries for the same string. The `llm` guideline documents the ones it
|
| 177 |
+
found (`annotation/GUIDELINES.md`).
|
| 178 |
+
|
| 179 |
+
### `llm`
|
| 180 |
+
|
| 181 |
+
A second annotation of the same sentences, produced in September 2026 by a large language
|
| 182 |
+
model prompted with `annotation/prompt-v2.2.md`, which embeds
|
| 183 |
+
`annotation/GUIDELINES.md` v2.2 in full. Pipeline, all in
|
| 184 |
+
`annotation/scripts/`: `select_sentences.py` → `build_requests.py` (batches of 50 sentences,
|
| 185 |
+
one guideline copy per batch) → `annotate.js` (calls the model, verifies the returned id set,
|
| 186 |
+
retries once, then bisects a failing batch) → `validate_responses.py` (re-aligns each
|
| 187 |
+
returned entity *string* onto the token sequence, rejects anything that does not align to
|
| 188 |
+
whole tokens) → `export_iob.py`.
|
| 189 |
+
|
| 190 |
+
**The guideline was inferred from the silver layer**, not written from linguistic
|
| 191 |
+
principles: each rule states the majority convention in the silver train split with the
|
| 192 |
+
counts behind it (e.g. `آقای` outside a `PER` span 140/141 times), and calls the minority out
|
| 193 |
+
as an error to correct. So the two configurations are not independent: `llm` is what the
|
| 194 |
+
silver conventions look like when applied consistently.
|
| 195 |
+
|
| 196 |
+
Three entity types were deliberately dropped. `MON`, `TIM` and `PCT` are 3.2% of silver
|
| 197 |
+
spans and the least consistent — the guideline could not find a majority convention to
|
| 198 |
+
state for them. Consumers wanting those types should use `silver`.
|
| 199 |
+
|
| 200 |
+
Model provenance is incomplete and recorded honestly: `annotate.js` was run with the model
|
| 201 |
+
alias `default` (the harness's session default) and the resolved model id, temperature
|
| 202 |
+
and date were not written into the output rows. Re-running the same prompt on a sample
|
| 203 |
+
agreed with the committed run at span F 0.95-0.98, so the committed files are the record of
|
| 204 |
+
origin and cannot be reproduced bit-exactly. `prompt_hash` is stable, so a re-run against a
|
| 205 |
+
changed guideline is detectable.
|
| 206 |
+
|
| 207 |
+
42 entities the model returned were rejected by `validate_responses.py` and are
|
| 208 |
+
listed in `llm/dropped-entities.jsonl` with the sentence they came from: 36 `no-align`, 5 `bad-label`, 1 `overlap`.
|
| 209 |
+
`no-align` means the returned string does not cover whole tokens, mostly a name the model
|
| 210 |
+
separated from its clitic (`فاطمه` against the token `فاطمهام`) or a span the model
|
| 211 |
+
re-spelled; `bad-label` is a label outside the four; `overlap` is a span inside another.
|
| 212 |
+
|
| 213 |
+
## Agreement between the two configurations
|
| 214 |
+
|
| 215 |
+
Exact span match, `silver` restricted to the four shared labels as the reference, from
|
| 216 |
+
`llm/agreement.json`:
|
| 217 |
+
|
| 218 |
+
| split | PER F | LOC F | ORG F | DAT F | micro P | micro R | micro F |
|
| 219 |
+
|---|---|---|---|---|---|---|---|
|
| 220 |
+
| train | 0.716 | 0.816 | 0.675 | 0.692 | 0.746 | 0.739 | **0.742** |
|
| 221 |
+
| dev | 0.723 | 0.795 | 0.706 | 0.747 | 0.755 | 0.741 | **0.748** |
|
| 222 |
+
| test | 0.734 | 0.827 | 0.679 | 0.706 | 0.761 | 0.747 | **0.754** |
|
| 223 |
+
|
| 224 |
+
Adjudicating every test-split disagreement span by span (LLM-judged, so an estimate) put the
|
| 225 |
+
`llm` annotations at 0.93-0.95 precision against silver's 0.84: silver is wrong or
|
| 226 |
+
mis-bounded on roughly 126 of its 783 test spans. That number is why `llm` exists; it is not
|
| 227 |
+
a measurement.
|
| 228 |
+
|
| 229 |
+
### Training the same model on each
|
| 230 |
+
|
| 231 |
+
Same spaCy NER architecture, same hyperparameters, same sentences; micro F over
|
| 232 |
+
`PER`/`LOC`/`ORG`/`DAT`, out-of-scope entities removed from both prediction and reference:
|
| 233 |
+
|
| 234 |
+
| trained on \ scored on | `silver` test | `llm` test |
|
| 235 |
+
|---|---|---|
|
| 236 |
+
| `silver` | **71.98** | 67.27 |
|
| 237 |
+
| `llm` | 67.59 | **79.94** |
|
| 238 |
+
|
| 239 |
+
The diagonal says the `llm` labels are more internally consistent (+7.96 F for an identical
|
| 240 |
+
model). The near-symmetric off-diagonal says the two conventions are genuinely different,
|
| 241 |
+
not one a subset of the other. `ORG` recall does *not* improve under `llm` (68.1 → 66.9): the
|
| 242 |
+
head-noun-plus-specifier construction (`کمیسیون آموزش`) is under-tagged in both. Details in
|
| 243 |
+
the pipeline repo's `docs/MODELS.md` §10.
|
| 244 |
+
|
| 245 |
+
## Limitations
|
| 246 |
+
|
| 247 |
+
- **No human gold.** Nothing on this card measures accuracy. A 200-sentence blind human
|
| 248 |
+
sample over the test split is drawn and unfilled; until it is, prefer `silver` for
|
| 249 |
+
reporting numbers comparable to prior PerDT work, and treat `llm` as a consistency-improved
|
| 250 |
+
training set whose real recall is unknown.
|
| 251 |
+
- **`llm` has four labels.** A seven-label model evaluated on it, or vice versa, needs the
|
| 252 |
+
label restriction described above.
|
| 253 |
+
- **Silver is silver.** Tagger output with corrections of unknown extent; the PerDT authors
|
| 254 |
+
used it to mark `PROPN`, not as an NER benchmark.
|
| 255 |
+
- **One sentence in `llm` is unannotated** (`train-s16861`, a content-filter refusal);
|
| 256 |
+
its `ner_tags` are all `O` and `error` is `"missing"`.
|
| 257 |
+
- **Genre.** Contemporary written Persian, news-heavy. No social media, no dialect.
|
| 258 |
+
- **Tokenization is spaCy-shaped.** Clitics are attached. Systems that split them need to
|
| 259 |
+
re-align.
|
| 260 |
+
|
| 261 |
+
## Licence and attribution
|
| 262 |
+
|
| 263 |
+
**CC BY-SA 4.0**, inherited: PerDT is CC BY-SA 4.0 and this is Adapted Material, so
|
| 264 |
+
ShareAlike applies to both configurations and to anything trained on them that constitutes
|
| 265 |
+
an adaptation. Full text and notice in `LICENSE`.
|
| 266 |
+
|
| 267 |
+
Please credit the treebank:
|
| 268 |
+
|
| 269 |
+
```bibtex
|
| 270 |
+
@inproceedings{rasooli-etal-2022-persian,
|
| 271 |
+
title = {The {P}ersian Dependency Treebank Made Universal},
|
| 272 |
+
author = {Rasooli, Mohammad Sadegh and Safari, Pegah and Moloodi, Amirsaeid and Nourian, Alireza},
|
| 273 |
+
booktitle = {Proceedings of the Thirteenth Language Resources and Evaluation Conference},
|
| 274 |
+
year = {2022},
|
| 275 |
+
pages = {7078--7087},
|
| 276 |
+
url = {https://aclanthology.org/2022.lrec-1.766}
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
@inproceedings{rasooli-etal-2013-development,
|
| 280 |
+
title = {Development of a {P}ersian Syntactic Dependency Treebank},
|
| 281 |
+
author = {Rasooli, Mohammad Sadegh and Kouhestani, Manouchehr and Moloodi, Amirsaeid},
|
| 282 |
+
booktitle = {Proceedings of NAACL-HLT 2013},
|
| 283 |
+
year = {2013},
|
| 284 |
+
url = {https://aclanthology.org/N13-1031}
|
| 285 |
+
}
|
| 286 |
+
```
|
| 287 |
+
|
| 288 |
+
and, for the `silver` layer's tagger:
|
| 289 |
+
|
| 290 |
+
```bibtex
|
| 291 |
+
@article{taher-etal-2020-beheshti,
|
| 292 |
+
title = {Beheshti-{NER}: {P}ersian named entity recognition Using {BERT}},
|
| 293 |
+
author = {Taher, Ehsan and Hoseini, Seyed Abbas and Shamsfard, Mehrnoush},
|
| 294 |
+
journal = {arXiv preprint arXiv:2003.08875},
|
| 295 |
+
year = {2020}
|
| 296 |
+
}
|
| 297 |
+
```
|
| 298 |
+
|
| 299 |
+
If you use the `llm` configuration or the annotation kit, cite this dataset:
|
| 300 |
+
|
| 301 |
+
```bibtex
|
| 302 |
+
@misc{fazeli-2026-fa-perdt-ner,
|
| 303 |
+
title = {fa-perdt-ner: {P}ersian NER over the {PerDT} treebank, silver and {LLM}-relabelled},
|
| 304 |
+
author = {Fazeli, Kiyarash},
|
| 305 |
+
year = {2026},
|
| 306 |
+
url = {https://huggingface.co/datasets/Phazel/fa-perdt-ner}
|
| 307 |
+
}
|
| 308 |
+
```
|
| 309 |
+
|
| 310 |
+
Source, build script and the full annotation history:
|
| 311 |
+
<https://github.com/Fazel94/spacy-persian> (`annotation/`, `scripts/annotation/`).
|
| 312 |
+
`manifest.json` in this repo records the commit each file was built from.
|
annotation/GUIDELINES.md
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Persian NER annotation guidelines, v2.2
|
| 2 |
+
|
| 3 |
+
Labels: `PER`, `LOC`, `ORG`, `DAT`. Everything else is `O`. Spans are contiguous token
|
| 4 |
+
sequences on the PerDT `--merge-subtokens` tokenization; an entity text must be reproducible
|
| 5 |
+
by joining consecutive tokens with single spaces.
|
| 6 |
+
|
| 7 |
+
These conventions were inferred from PerDT's silver NER layer (Beheshti-NER output with manual
|
| 8 |
+
corrections, `corpus/perdt-ner-iob/train.txt`, 26,196 sentences) so that new annotations agree
|
| 9 |
+
with the bulk of the existing data. Where the silver layer is inconsistent, the majority rule
|
| 10 |
+
is stated and the minority is called out as an error to correct. Counts are train-split.
|
| 11 |
+
|
| 12 |
+
## General
|
| 13 |
+
|
| 14 |
+
1. Annotate every mention, including repeats within a sentence.
|
| 15 |
+
2. Do not nest or overlap. The longest span that is itself a name wins:
|
| 16 |
+
`دانشگاه تهران` is one `ORG`, not `ORG` around a `LOC`; `شرکت مخابرات ایران` is one `ORG`.
|
| 17 |
+
3. Coordinated names are separate spans: `ایران و عراق` is `LOC` + `LOC`.
|
| 18 |
+
4. Nationality and language adjectives and demonyms are `O`: `ایرانی` (181/181 `O`),
|
| 19 |
+
`آمریکایی`, `ایرانیان`, `مسلمانان`, `فارسی`, `انگلیسی`.
|
| 20 |
+
5. Religions, ideologies, scriptures and literary works are `O`: `اسلام`, `قرآن`, `شاهنامه`.
|
| 21 |
+
6. Generic role nouns are `O` and sit outside the span: `رئیس جمهور ایران` labels only
|
| 22 |
+
`ایران` (`LOC`); `وزیر` and `رئیس` precede `ORG` spans but are never inside them.
|
| 23 |
+
|
| 24 |
+
## PER
|
| 25 |
+
|
| 26 |
+
7. Personal names, including religious and historical figures: `علی`, `احمدینژاد`,
|
| 27 |
+
`داریوش`, `اوباما`, `پیامبر`, `رسول خدا`, `امام حسین`.
|
| 28 |
+
8. Secular honorifics and titles are `O`, outside the span: `آقای` (140/141 `O`), `دکتر`
|
| 29 |
+
(104/107 `O`), `آیتالله`, `استاد`, `ارتشبد`. `آقای احمدینژاد` → `[احمدینژاد]`.
|
| 30 |
+
9. Religious titles fused with the name are inside the span: `امام` (217 `B-PER`), `حضرت`
|
| 31 |
+
(129 `B-PER`), `سید`: `[امام صادق]`, `[حضرت علی]`, `[سید محمدحسن ابوترابیفرد]`.
|
| 32 |
+
10. Blessing formulas: the spelled-out `علیهالسلام` directly after a name is inside the span
|
| 33 |
+
(88/98): `[امام صادق علیهالسلام]`. The abbreviated parenthetical `( ع )` / `( ص )` is
|
| 34 |
+
entirely `O`: `[امام حسین] ( ع )`. (The silver layer tags the opening `(` as `I-PER` 295
|
| 35 |
+
times; that is a tokenization artefact, correct it.)
|
| 36 |
+
11. `خدا` and `الله` alone are `O` (520/566); `رسول خدا` as a name of the Prophet is `PER`.
|
| 37 |
+
12. Patronymic chains are one span: `[احمد بن محمد بن عیسی]`.
|
| 38 |
+
|
| 39 |
+
## LOC
|
| 40 |
+
|
| 41 |
+
13. Countries, cities, provinces, regions, continents, bodies of water, planets:
|
| 42 |
+
`ایران`, `تهران`, `خاورمیانه`, `اروپا`, `خلیج فارس`, `مریخ`.
|
| 43 |
+
14. Geographic head nouns are INSIDE the span when directly followed by the name:
|
| 44 |
+
`[شهر تهران]` (88 vs 4), `[استان گلستان]` (69 vs 0), `[منطقهٔ ...]` (32 vs 4),
|
| 45 |
+
`[کشور روسیه]` (27 vs 5). Alone, without a name, they are `O` (`کشور` alone 440 `O`).
|
| 46 |
+
15. `جهان` ("the world") is `LOC` when it denotes the world as a place (`در جهان`,
|
| 47 |
+
`بزرگترین تالاب جهان`), 202 vs 87. `زمین` is `LOC` only as the planet (`کرهٔ زمین`),
|
| 48 |
+
otherwise `O` (250 `O`).
|
| 49 |
+
16. Metonymic country/capital names acting as governments stay `LOC`: `تهران اعلام کرد`.
|
| 50 |
+
17. `مردم ایران`, `ملت ایران`: only `ایران` is labelled.
|
| 51 |
+
18. Compass terms are `O` unless they are part of a named region: `غرب` alone `O`
|
| 52 |
+
(84 vs 15), and `غرب` meaning "the West" as a civilisation or political bloc is `O`
|
| 53 |
+
too (`مدلبرداری از غرب`, `پوششهای مبتذل غرب`). `[غرب تهران]`, `[خاورمیانه]` are `LOC`.
|
| 54 |
+
|
| 55 |
+
## ORG
|
| 56 |
+
|
| 57 |
+
19. Companies, institutions, ministries, parties, armed groups, sports clubs, media outlets,
|
| 58 |
+
banks, universities, international bodies: `گوگل`, `طالبان`, `استقلال`, `سازمان ملل`,
|
| 59 |
+
`بانک مرکزی`, `مجلس شورای اسلامی`, `صدا و سیما`, `اینترپل`, `ساواک`.
|
| 60 |
+
20. Organisational head nouns are INSIDE the span when followed by a specifier:
|
| 61 |
+
`[دولت ایران]`, `[وزارت امور خارجه]`, `[شرکت مخابرات ایران]`, `[تیم استقلال]`,
|
| 62 |
+
`[سفارت ایران]`, `[ارتش دریایی ایران]`, `[دانشگاه تهران]`, `[تیم ملی بوکس]`.
|
| 63 |
+
A head noun with no specifier is `O`, even when it clearly denotes one institution in
|
| 64 |
+
context: `دولت` alone 221 `O`, `تیم` 129 `O`, `مجلس` 132 `O`, and likewise bare
|
| 65 |
+
`شهرداری`, `فدراسیون`, `وزارت`, `سفارت`, `دانشگاه`, `تیم ملی`. "The municipality
|
| 66 |
+
collects its dues" labels nothing; `[شهرداری تهران]` is `ORG`.
|
| 67 |
+
21. A country name inside such a phrase belongs to the `ORG` span, not a separate `LOC`
|
| 68 |
+
(103 `ORG` spans end in `ایران`).
|
| 69 |
+
22. Political entities named as states are `ORG`: `جمهوری اسلامی`, `جمهوری اسلامی ایران`,
|
| 70 |
+
`رژیم صهیونیستی`, `رژیم ایران`.
|
| 71 |
+
23. News agencies cited as sources are `ORG`: `به گزارش خبرنگار [مهر]`.
|
| 72 |
+
|
| 73 |
+
## DAT
|
| 74 |
+
|
| 75 |
+
24. Absolute dates and years, including the head noun `سال`/`ماه`/`روز` when present:
|
| 76 |
+
`[سال 1974]`, `[ماه رمضان]`, `[روز جمعه]`, `[سیام اکتبر سال 1910]`,
|
| 77 |
+
`[سال هزار و هشتصد و یازده]`, `[ماه ژوئن سال 2011]`.
|
| 78 |
+
25. Relative date expressions are `DAT`: `امروز` (149), `فردا`, `دیروز`, `امسال`,
|
| 79 |
+
`[سال گذشته]`, `[سال جاری]`, `[هفتهٔ آینده]`, `[این هفته]` (10 vs 0), `[روز گذشته]`.
|
| 80 |
+
The vague deictics `این روزها` (0/24), `این ماه` (0/6) and `این سال` (0/3) are `O`:
|
| 81 |
+
the silver layer treats them as "nowadays", not as a dated period.
|
| 82 |
+
26. Durations anchored to now are `DAT`: `[10 سال پیش]`, `[سه دهه پیش]`, `[یک ماه قبل]`.
|
| 83 |
+
Unanchored durations are `O`: `به مدت سه سال`.
|
| 84 |
+
27. A date range with `از ... تا/الی ...` is ONE span including `از` and `تا`:
|
| 85 |
+
`[از بهمن 1343 تا خرداد 1357]`, `[از سال 1375 تا سال 1386]`, `[از 420 تا 438 میلادی]`.
|
| 86 |
+
`[از آغاز امسال] تاکنون`: `تاکنون` is outside.
|
| 87 |
+
28. Calendar suffixes are inside: `[سال 1251 شمسی]`, `[438 میلادی]`; the abbreviated
|
| 88 |
+
`ه . ش` after a year is outside.
|
| 89 |
+
29. Eras and dynasties as periods are `O` (`هخامنشی`, `ساسانی`), and so are historic
|
| 90 |
+
empires named after them (`امپراطوری پارس`); named festivals `نوروز`, `عاشورا` are
|
| 91 |
+
`O` on their own (`نوروز` 30 `O` vs 3 `DAT`, `عاشورا` 41/0), including attributive
|
| 92 |
+
use (`تشریفات نوروز`). A festival phrase headed by `سال`/`ماه`/`روز`, or carrying a
|
| 93 |
+
year, is `DAT` under rule 24: `[ماه رمضان]`, `[سال نو چینی]`, `[نوروز امسال]`.
|
| 94 |
+
30. Times of day, clock times, money and percentages are `O` in this label set.
|
| 95 |
+
|
| 96 |
+
## Cases v1 left open, decided in v2
|
| 97 |
+
|
| 98 |
+
31. Events are `O`. The label set has no EVENT class, and an event is not the organisation
|
| 99 |
+
that runs it: `نمایشگاه CES`, `جام جهانی`, `المپیک`, `لیگ قهرمانان آسیا` are all `O`.
|
| 100 |
+
The organising or competing body is still `ORG` when named: `[فدراسیون فوتبال]`.
|
| 101 |
+
32. Habitual and frequency expressions are `O`: `هر روز`, `هر شب`, `هر هفته`, `روزانه`,
|
| 102 |
+
`همهروزه`. Only absolute dates (rule 24), relative dates (rule 25) and now-anchored
|
| 103 |
+
durations (rule 26) are `DAT`. `هر روز` is a habit; `امروز` is a date.
|
| 104 |
+
33. A religious title is part of a `PER` span only when a personal name follows it
|
| 105 |
+
(rule 9): `[امام صادق]`, `[حضرت علی]`, `[امام خمینی]`. Standing alone it is `O`,
|
| 106 |
+
whatever it refers to in context: `امام` with no name following is `O` 128 times
|
| 107 |
+
against 12 `PER`, `حضرت` 81 against 3. So `حضرت فرمودند`, `آن حضرت`, `به محضر حضرت`
|
| 108 |
+
and `امام ( ع ) فرمود` label nothing. Collective references are `O` as well:
|
| 109 |
+
`ائمهٔ اطهار`, `اهلبیت`, `معصومین`. `پیامبر` and `رسول خدا` stay `PER` (rule 7):
|
| 110 |
+
they are used as the name of one person, not as a title before a name.
|
| 111 |
+
34. Peoples, tribes and ethnic groups are `O`, consistent with rule 4: `قوم مایا`,
|
| 112 |
+
`ترکمن`, `اعراب`, `کردها`. A place named after such a group is still `LOC`.
|
| 113 |
+
35. A personal name used as an epithet is still `PER`: `[امیرکبیر] فوتبال ایران`. The name
|
| 114 |
+
is the entity; the metaphor does not change that. (The silver layer usually leaves
|
| 115 |
+
these unlabelled; this is a deliberate deviation.)
|
| 116 |
+
36. `دنیا` is `O`, and does NOT follow rule 15 the way `جهان` does. The two words diverge
|
| 117 |
+
sharply in the silver layer: `جهان` is `LOC` 202 times against 87 `O`, while `دنیا` is
|
| 118 |
+
`O` 240 times against 20 `LOC`. So `در سراسر دنیا` and `قفس دنیا` label nothing, while
|
| 119 |
+
`در جهان` is `LOC`.
|
| 120 |
+
37. Century expressions are `DAT`, including the head noun and any calendar suffix:
|
| 121 |
+
`[قرن سوم هجری]`, `[قرن بیستم]`, `[اوایل قرن نوزدهم]`.
|
| 122 |
+
38. Brands, products, software and vehicle models are `O`: `بنز`, `فتوشاپ`, `ویندوز`,
|
| 123 |
+
`فایرفاکس`. The company behind them is `ORG` when the sentence names the company
|
| 124 |
+
(`[شرکت مایکروسافت]`), not when it names the product.
|
| 125 |
+
39. Deities, angels and mythological beings are `O`, extending rule 11: `خدا`, `الله`,
|
| 126 |
+
`یزدان`, `شیطان`, `ابلیس`, `جبرئیل`. Prophets and imams named as people stay `PER`.
|
| 127 |
+
40. Religious denominations, theological and philosophical schools, and political
|
| 128 |
+
movements are `O`, extending rule 5: `شیعه` (41 `O`), `سنی` (28), `معتزله` (5),
|
| 129 |
+
`اشاعره`, `صوفیه`, `مارکسیسم` (4). A named organisation belonging to one is still
|
| 130 |
+
`ORG` (`[حزب توده]`).
|
| 131 |
+
|
| 132 |
+
## Changelog
|
| 133 |
+
|
| 134 |
+
v2, derived from adjudicating 500 annotated sentences against the silver layer
|
| 135 |
+
(`annotation/data/llm/ner-v1-default/pool-500.agreement.json`):
|
| 136 |
+
|
| 137 |
+
- Rules 31–37 added. 31–34 close gaps that produced most of the real annotation errors
|
| 138 |
+
under v1 (events tagged `ORG`, habituals tagged `DAT`, collective religious references
|
| 139 |
+
tagged `PER`, ethnonyms tagged `LOC`). 35–37 decide cases where v1 was silent.
|
| 140 |
+
- Rules 18, 20 and 29 were already correct but were violated repeatedly, so each now names
|
| 141 |
+
the exact forms that were mislabelled: `غرب` as "the West", bare `شهرداری`/`فدراسیون`/
|
| 142 |
+
`مجلس`/`تیم ملی`, and bare `نوروز`.
|
| 143 |
+
- Rules 1–17, 19, 21–28, 30 are unchanged from v1. Numbering is stable across versions.
|
| 144 |
+
- A first v2 draft over-corrected: it dropped `[کلینیک نور]` (`ORG` with a name, rule 20).
|
| 145 |
+
Rules 25 and 29 were re-checked against train-split counts (`این روزها` 0/24 `O`,
|
| 146 |
+
`نوروز` 30 `O` vs 3 `DAT`) and now state both directions explicitly.
|
| 147 |
+
|
| 148 |
+
v2.1, after annotating the full 1455-sentence test split and adjudicating every
|
| 149 |
+
disagreement:
|
| 150 |
+
|
| 151 |
+
- Rule 33 is reverted and rewritten. v2 claimed a bare `امام`/`حضرت` denoting a specific
|
| 152 |
+
person is `PER`, generalising from 11 instances of `امام (`. The base rate contradicts
|
| 153 |
+
it: with no personal name following, `امام` is `O` 128 times against 12 `PER` and
|
| 154 |
+
`حضرت` 81 against 3. That single rule caused 7 of the 19 real annotation errors left on
|
| 155 |
+
the full split.
|
| 156 |
+
- Rules 38 (brands and products) and 39 (deities and mythological beings) added; they
|
| 157 |
+
cover 5 more of those 19 errors (`بنز`, `فتوشاپ`, `جاماسپ`, `شیطان`, `یزدان`).
|
| 158 |
+
|
| 159 |
+
v2.2, after relabelling the first 2,000 train sentences (largely literary and memoir prose,
|
| 160 |
+
a genre the test split barely contains):
|
| 161 |
+
|
| 162 |
+
- Rule 36 is reversed. v2.1 claimed `دنیا` behaves like `جهان`; the silver layer says the
|
| 163 |
+
opposite, `دنیا` `O` 240 against 20 `LOC` while `جهان` is `LOC` 202 against 87 `O`.
|
| 164 |
+
- Rule 40 added: denominations, theological schools and political movements are `O`
|
| 165 |
+
(`شیعه` 41 `O`, `سنی` 28, `معتزله` 5, `مارکسیسم` 4). `معتزله` tagged `ORG` was an error
|
| 166 |
+
with no rule to prevent it.
|
annotation/prompt-v2.2.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
You are annotating Persian sentences for named entities. Labels: PER, LOC, ORG, DAT.
|
| 2 |
+
Follow the guideline below exactly; it was derived from the corpus and overrides your own
|
| 3 |
+
intuition where they differ.
|
| 4 |
+
|
| 5 |
+
Output rules:
|
| 6 |
+
- Return one item per input id, every id, no extra ids.
|
| 7 |
+
- For each entity return `text` copied character-for-character from the sentence (same
|
| 8 |
+
spaces, same ZWNJ U+200C, same digits) and `label`.
|
| 9 |
+
- List entities in sentence order. Repeat mentions are separate entities.
|
| 10 |
+
- A sentence with no entity gets an empty `entities` list.
|
| 11 |
+
- Never nest or overlap spans. Never include honorifics آقای/دکتر, the parenthetical ( ع ) /
|
| 12 |
+
( ص ), or role nouns like رئیس/وزیر.
|
| 13 |
+
- `label` must be exactly one of PER, LOC, ORG, DAT. Never emit O; to mark something as not
|
| 14 |
+
an entity, leave it out.
|
| 15 |
+
|
| 16 |
+
These are the mistakes made most often on this corpus. Check every candidate span against
|
| 17 |
+
this list before returning it, in both directions — the rule tells you what to drop AND what
|
| 18 |
+
to keep:
|
| 19 |
+
- An organisational head noun with NO proper name after it is not an entity: شهرداری،
|
| 20 |
+
فدراسیون، مجلس، دولت، وزارت، سفارت، دانشگاه، تیم، تیم ملی. As soon as a name or
|
| 21 |
+
specifier follows, the whole phrase is ORG: شهرداری تهران، دولت ایران، تیم ملی بوکس،
|
| 22 |
+
کلینیک نور، وزارت امور خارجه، دانشگاه تهران.
|
| 23 |
+
- A bare compass term is not an entity, including غرب meaning "the West" as a civilisation
|
| 24 |
+
or bloc. غرب تهران is LOC.
|
| 25 |
+
- Events are not entities: جام جهانی، المپیک، نمایشگاه CES، لیگ قهرمانان آسیا. The body
|
| 26 |
+
that runs or plays in them is ORG when named.
|
| 27 |
+
- Habituals are not dates: هر روز، هر شب، هر هفته، روزانه. Nor are the vague deictics این
|
| 28 |
+
روزها، این ماه، این سال. But امروز، دیروز، این هفته، سال گذشته، همین حالا-type relative
|
| 29 |
+
dates ARE dates, and so are قرن بیستم، قرن سوم هجری.
|
| 30 |
+
- A festival name alone is not a date: نوروز، عاشورا، تشریفات نوروز. With a date head noun
|
| 31 |
+
or a year it is: ماه رمضان، سال نو چینی، نوروز امسال.
|
| 32 |
+
- A religious title counts only when a personal name follows it: امام صادق، حضرت علی are
|
| 33 |
+
persons. Alone it is nothing, however specific the reference: حضرت فرمودند، آن حضرت، امام
|
| 34 |
+
( ع ) فرمود tag nothing. Collective references tag nothing either: ائمهٔ اطهار، اهلبیت،
|
| 35 |
+
معصومین. پیامبر and رسول خدا are persons.
|
| 36 |
+
- Brands, products and software are not organisations: بنز، فتوشاپ، ویندوز، فایرفاکس. The
|
| 37 |
+
company is ORG only when the sentence names the company: شرکت مایکروسافت.
|
| 38 |
+
- Deities and mythological beings are not persons: خدا، الله، یزدان، شیطان، جبرئیل.
|
| 39 |
+
- Peoples and ethnic groups are not places: قوم مایا، ترکمن، اعراب. Denominations,
|
| 40 |
+
theological schools and political movements are not organisations: شیعه، سنی، معتزله،
|
| 41 |
+
صوفیه، مارکسیسم.
|
| 42 |
+
- دنیا is never a place, however it is used: در سراسر دنیا، قفس دنیا tag nothing. جهان
|
| 43 |
+
usually is one: در جهان، بزرگترین تالاب جهان are LOC.
|
| 44 |
+
|
| 45 |
+
<guideline>
|
| 46 |
+
{{GUIDELINES}}
|
| 47 |
+
</guideline>
|
annotation/scripts/annotate.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// LLM NER annotator. Runs inside the harness JS eval kernel because `completion()` only
|
| 2 |
+
// exists there. Invoke from an eval cell:
|
| 3 |
+
//
|
| 4 |
+
// globalThis.ANNOTATE = {
|
| 5 |
+
// jobs: [{ requests: "<abs>/…/shard-000.jsonl", responses: "<abs>/…/shard-000.jsonl" }, …],
|
| 6 |
+
// cache: "<abs>/annotation/work/cache",
|
| 7 |
+
// model: "default", concurrency: 16,
|
| 8 |
+
// };
|
| 9 |
+
// await (0, eval)(await Bun.file("<abs>/scripts/annotation/annotate.js").text());
|
| 10 |
+
//
|
| 11 |
+
// A single `{requests, responses}` pair may be given at the top level instead of `jobs`.
|
| 12 |
+
// Every batch of every job goes into ONE work queue, so `concurrency` is the real number of
|
| 13 |
+
// in-flight model calls no matter how the work is split across files; shard boundaries cost
|
| 14 |
+
// nothing in throughput.
|
| 15 |
+
//
|
| 16 |
+
// Indirect eval runs in global scope, so `completion` resolves. Everything lives inside one
|
| 17 |
+
// async IIFE so the file can be evaluated repeatedly without lexical redeclaration errors.
|
| 18 |
+
//
|
| 19 |
+
// Per request line: cache hit -> reuse; else call the model, verify the returned id set
|
| 20 |
+
// equals the requested one, retry once on mismatch, then split the batch in half and
|
| 21 |
+
// re-issue each half. A call that throws (rate limit, transport) is retried with backoff and
|
| 22 |
+
// then recorded as failed; failures are never cached, so re-running resumes exactly the
|
| 23 |
+
// batches that did not land.
|
| 24 |
+
|
| 25 |
+
(async () => {
|
| 26 |
+
const cfg = globalThis.ANNOTATE;
|
| 27 |
+
if (!cfg) throw new Error("set globalThis.ANNOTATE before evaluating annotate.js");
|
| 28 |
+
if (typeof completion === "undefined") {
|
| 29 |
+
throw new Error("completion() is not visible; paste this file's body into the eval cell");
|
| 30 |
+
}
|
| 31 |
+
const model = cfg.model ?? "default";
|
| 32 |
+
const concurrency = cfg.concurrency ?? 8;
|
| 33 |
+
const attempts = cfg.attempts ?? 3;
|
| 34 |
+
const jobs = cfg.jobs ?? [{ requests: cfg.requests, responses: cfg.responses }];
|
| 35 |
+
const INSTRUCTION = "Annotate every sentence. Return one item per id.";
|
| 36 |
+
|
| 37 |
+
const { mkdir, writeFile } = await import("node:fs/promises");
|
| 38 |
+
const path = await import("node:path");
|
| 39 |
+
|
| 40 |
+
await mkdir(cfg.cache, { recursive: true });
|
| 41 |
+
const queue = [];
|
| 42 |
+
for (const [j, job] of jobs.entries()) {
|
| 43 |
+
const text = await Bun.file(job.requests).text();
|
| 44 |
+
const reqs = text.split("\n").filter((l) => l.trim()).map((l) => JSON.parse(l));
|
| 45 |
+
job.results = new Array(reqs.length);
|
| 46 |
+
await mkdir(path.dirname(job.responses), { recursive: true });
|
| 47 |
+
reqs.forEach((req, i) => queue.push({ job: j, index: i, req }));
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
const stats = { cached: 0, called: 0, retried: 0, errored: 0, failed: 0 };
|
| 51 |
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
| 52 |
+
const parse = (raw) => (typeof raw === "string" ? JSON.parse(raw) : raw);
|
| 53 |
+
|
| 54 |
+
const bodyFor = (req, ids) => {
|
| 55 |
+
const byId = new Map(req.sentences.map((s) => [s.id, s.text]));
|
| 56 |
+
return INSTRUCTION + "\n\n" + ids.map((id) => `${id}: ${byId.get(id)}`).join("\n");
|
| 57 |
+
};
|
| 58 |
+
|
| 59 |
+
// One model call, retried through transport/rate-limit errors before giving up.
|
| 60 |
+
const ask = async (req, ids) => {
|
| 61 |
+
for (let a = 1; ; a++) {
|
| 62 |
+
try {
|
| 63 |
+
stats.called += 1;
|
| 64 |
+
const out = parse(
|
| 65 |
+
await completion(bodyFor(req, ids), { model, system: req.system, schema: req.schema }).wait(),
|
| 66 |
+
);
|
| 67 |
+
const items = Array.isArray(out?.items) ? out.items : [];
|
| 68 |
+
const want = new Set(ids);
|
| 69 |
+
const got = new Set(items.map((i) => i.id));
|
| 70 |
+
const ok = got.size === want.size && [...want].every((id) => got.has(id));
|
| 71 |
+
return { items: items.filter((i) => want.has(i.id)), ok };
|
| 72 |
+
} catch (err) {
|
| 73 |
+
stats.errored += 1;
|
| 74 |
+
if (a >= attempts) {
|
| 75 |
+
console.log(` call failed on ${req.batch} after ${a} attempts: ${err?.message ?? err}`);
|
| 76 |
+
return { items: [], ok: false, threw: true };
|
| 77 |
+
}
|
| 78 |
+
await sleep(1000 * 2 ** (a - 1));
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
};
|
| 82 |
+
|
| 83 |
+
const run = async (req, ids, depth = 0) => {
|
| 84 |
+
let attempt = await ask(req, ids);
|
| 85 |
+
if (attempt.ok) return { items: attempt.items, error: null };
|
| 86 |
+
// A thrown call (transport, rate limit, content refusal) is not necessarily the whole
|
| 87 |
+
// batch's fault: a single sentence can trigger a refusal. Bisect so the rest still lands.
|
| 88 |
+
if (attempt.threw && ids.length === 1) return { items: [], error: "call-failed" };
|
| 89 |
+
if (!attempt.threw && depth === 0) {
|
| 90 |
+
stats.retried += 1;
|
| 91 |
+
attempt = await ask(req, ids);
|
| 92 |
+
if (attempt.ok) return { items: attempt.items, error: null };
|
| 93 |
+
}
|
| 94 |
+
if (ids.length > 1 && (attempt.threw || depth < 2)) {
|
| 95 |
+
const mid = Math.ceil(ids.length / 2);
|
| 96 |
+
const [ra, rb] = [
|
| 97 |
+
await run(req, ids.slice(0, mid), depth + 1),
|
| 98 |
+
await run(req, ids.slice(mid), depth + 1),
|
| 99 |
+
];
|
| 100 |
+
const errs = [ra.error, rb.error].filter(Boolean);
|
| 101 |
+
return { items: [...ra.items, ...rb.items], error: errs.length ? errs[0] : null };
|
| 102 |
+
}
|
| 103 |
+
console.log(` id-mismatch on ${req.batch} ids=${ids.join(",")}`);
|
| 104 |
+
return { items: attempt.items, error: "id-mismatch" };
|
| 105 |
+
};
|
| 106 |
+
|
| 107 |
+
let next = 0;
|
| 108 |
+
const worker = async () => {
|
| 109 |
+
for (;;) {
|
| 110 |
+
const slot = next++;
|
| 111 |
+
if (slot >= queue.length) return;
|
| 112 |
+
const { job: j, index, req } = queue[slot];
|
| 113 |
+
const cacheFile = path.join(cfg.cache, `${req.cache_key}.json`);
|
| 114 |
+
if (await Bun.file(cacheFile).exists()) {
|
| 115 |
+
jobs[j].results[index] = JSON.parse(await Bun.file(cacheFile).text());
|
| 116 |
+
stats.cached += 1;
|
| 117 |
+
continue;
|
| 118 |
+
}
|
| 119 |
+
if (cfg.cacheOnly) {
|
| 120 |
+
jobs[j].results[index] = {
|
| 121 |
+
batch: req.batch, model, prompt_hash: req.prompt_hash, items: [],
|
| 122 |
+
error: "uncached", failed_ids: req.ids,
|
| 123 |
+
};
|
| 124 |
+
stats.failed += 1;
|
| 125 |
+
continue;
|
| 126 |
+
}
|
| 127 |
+
const { items, error } = await run(req, req.ids);
|
| 128 |
+
const record = {
|
| 129 |
+
batch: req.batch,
|
| 130 |
+
model,
|
| 131 |
+
prompt_hash: req.prompt_hash,
|
| 132 |
+
items,
|
| 133 |
+
error,
|
| 134 |
+
...(error ? { failed_ids: req.ids.filter((id) => !items.some((it) => it.id === id)) } : {}),
|
| 135 |
+
};
|
| 136 |
+
jobs[j].results[index] = record;
|
| 137 |
+
if (error) stats.failed += 1;
|
| 138 |
+
else await writeFile(cacheFile, JSON.stringify(record), "utf8");
|
| 139 |
+
}
|
| 140 |
+
};
|
| 141 |
+
|
| 142 |
+
const t0 = Date.now();
|
| 143 |
+
await Promise.all(Array.from({ length: concurrency }, worker));
|
| 144 |
+
|
| 145 |
+
for (const job of jobs) {
|
| 146 |
+
await writeFile(job.responses, job.results.map((r) => JSON.stringify(r)).join("\n") + "\n", "utf8");
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
const secs = (Date.now() - t0) / 1000;
|
| 150 |
+
const line = `jobs=${jobs.length} batches=${queue.length} cached=${stats.cached} called=${stats.called}`
|
| 151 |
+
+ ` retried=${stats.retried} call_errors=${stats.errored} failed=${stats.failed}`
|
| 152 |
+
+ ` concurrency=${concurrency} elapsed=${secs.toFixed(1)}s (${(queue.length / secs).toFixed(2)} batches/s)`;
|
| 153 |
+
console.log(line);
|
| 154 |
+
return line;
|
| 155 |
+
})()
|
annotation/scripts/build_requests.py
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
"""Build batched annotation requests for the LLM NER kit.
|
| 3 |
+
|
| 4 |
+
Renders the system prompt by substituting `{{GUIDELINES}}` in the prompt template with the
|
| 5 |
+
full text of GUIDELINES.md, so the guideline is the single source of truth: editing it
|
| 6 |
+
changes `prompt_hash` and therefore every `cache_key`, invalidating stale responses.
|
| 7 |
+
|
| 8 |
+
python scripts/annotation/build_requests.py \
|
| 9 |
+
--input annotation/data/select-100.jsonl \
|
| 10 |
+
--prompt annotation/prompts/ner-v1.md \
|
| 11 |
+
--batch 10 --out annotation/work/requests/select-100.jsonl
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
+
import argparse
|
| 15 |
+
import hashlib
|
| 16 |
+
import json
|
| 17 |
+
from pathlib import Path
|
| 18 |
+
|
| 19 |
+
INSTRUCTION = "Annotate every sentence. Return one item per id."
|
| 20 |
+
|
| 21 |
+
SCHEMA = {
|
| 22 |
+
"type": "object",
|
| 23 |
+
"properties": {
|
| 24 |
+
"items": {
|
| 25 |
+
"type": "array",
|
| 26 |
+
"items": {
|
| 27 |
+
"type": "object",
|
| 28 |
+
"properties": {
|
| 29 |
+
"id": {"type": "string"},
|
| 30 |
+
"entities": {
|
| 31 |
+
"type": "array",
|
| 32 |
+
"items": {
|
| 33 |
+
"type": "object",
|
| 34 |
+
"properties": {
|
| 35 |
+
"text": {"type": "string"},
|
| 36 |
+
"label": {"type": "string", "enum": ["PER", "LOC", "ORG", "DAT"]},
|
| 37 |
+
},
|
| 38 |
+
"required": ["text", "label"],
|
| 39 |
+
},
|
| 40 |
+
},
|
| 41 |
+
},
|
| 42 |
+
"required": ["id", "entities"],
|
| 43 |
+
},
|
| 44 |
+
}
|
| 45 |
+
},
|
| 46 |
+
"required": ["items"],
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def sha256(s):
|
| 51 |
+
return hashlib.sha256(s.encode("utf8")).hexdigest()
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def render_prompt(prompt_path, guidelines_path):
|
| 55 |
+
template = prompt_path.read_text(encoding="utf8")
|
| 56 |
+
if "{{GUIDELINES}}" not in template:
|
| 57 |
+
raise SystemExit(f"{prompt_path} has no {{{{GUIDELINES}}}} placeholder")
|
| 58 |
+
return template.replace("{{GUIDELINES}}", guidelines_path.read_text(encoding="utf8").strip())
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def main():
|
| 62 |
+
ap = argparse.ArgumentParser(description=__doc__)
|
| 63 |
+
ap.add_argument("--input", required=True)
|
| 64 |
+
ap.add_argument("--prompt", default="annotation/prompts/ner-v2.2.md")
|
| 65 |
+
ap.add_argument("--guidelines", default="annotation/GUIDELINES.md")
|
| 66 |
+
# 20 measured on pool-500 against batch 10, same prompt: 25/25 batches returned every
|
| 67 |
+
# id with no retry, micro F vs silver 0.7778 against 0.7789, and the two runs agree at
|
| 68 |
+
# F 0.976 — tighter than run-to-run noise at a fixed batch size (0.949-0.951).
|
| 69 |
+
ap.add_argument("--batch", type=int, default=20)
|
| 70 |
+
ap.add_argument("--model", default="default")
|
| 71 |
+
ap.add_argument("--out", required=True)
|
| 72 |
+
args = ap.parse_args()
|
| 73 |
+
|
| 74 |
+
system = render_prompt(Path(args.prompt), Path(args.guidelines))
|
| 75 |
+
prompt_hash = sha256(system)[:12]
|
| 76 |
+
|
| 77 |
+
sents = [json.loads(line) for line in Path(args.input).open(encoding="utf8")]
|
| 78 |
+
out = Path(args.out)
|
| 79 |
+
out.parent.mkdir(parents=True, exist_ok=True)
|
| 80 |
+
name = out.name[: -len(".jsonl")] if out.name.endswith(".jsonl") else out.name
|
| 81 |
+
|
| 82 |
+
n = 0
|
| 83 |
+
with out.open("w", encoding="utf8") as fh:
|
| 84 |
+
for i in range(0, len(sents), args.batch):
|
| 85 |
+
chunk = sents[i : i + args.batch]
|
| 86 |
+
pairs = [{"id": s["id"], "text": s["text"]} for s in chunk]
|
| 87 |
+
lines = [f"{p['id']}: {p['text']}" for p in pairs]
|
| 88 |
+
body = INSTRUCTION + "\n\n" + "\n".join(lines)
|
| 89 |
+
req = {
|
| 90 |
+
"batch": f"{name}/{i // args.batch:03d}",
|
| 91 |
+
"model": args.model,
|
| 92 |
+
"ids": [p["id"] for p in pairs],
|
| 93 |
+
"sentences": pairs,
|
| 94 |
+
"system": system,
|
| 95 |
+
"body": body,
|
| 96 |
+
"schema": SCHEMA,
|
| 97 |
+
"prompt_hash": prompt_hash,
|
| 98 |
+
"cache_key": sha256(prompt_hash + args.model + "\n".join(lines)),
|
| 99 |
+
}
|
| 100 |
+
fh.write(json.dumps(req, ensure_ascii=False) + "\n")
|
| 101 |
+
n += 1
|
| 102 |
+
|
| 103 |
+
print(f"requests={n} sentences={len(sents)} batch={args.batch} model={args.model} "
|
| 104 |
+
f"prompt_hash={prompt_hash} -> {out}")
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
if __name__ == "__main__":
|
| 108 |
+
main()
|
annotation/scripts/compare_to_silver.py
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
"""Compare token-aligned LLM annotations against the PerDT silver layer.
|
| 3 |
+
|
| 4 |
+
python scripts/annotation/compare_to_silver.py \
|
| 5 |
+
--llm annotation/data/llm/ner-v1-default/select-100.jsonl \
|
| 6 |
+
--ref annotation/data/select-100.jsonl \
|
| 7 |
+
--out annotation/data/llm/ner-v1-default/select-100.agreement.json
|
| 8 |
+
|
| 9 |
+
Exact span match (start, end, label); silver is the reference, so "precision" reads as
|
| 10 |
+
"share of LLM spans the silver layer also has". Silver is not gold — the disagreement list
|
| 11 |
+
is the human review queue, not an error list. `expected_corrections` counts silver spans
|
| 12 |
+
that end on an opening parenthesis, the tokenization artefact GUIDELINES.md rule 10 tells
|
| 13 |
+
the annotator to correct, so those disagreements are not read as LLM mistakes.
|
| 14 |
+
|
| 15 |
+
With --self <other llm jsonl>, also reports span agreement between two LLM runs over their
|
| 16 |
+
overlapping ids (a run-to-run consistency sample).
|
| 17 |
+
"""
|
| 18 |
+
|
| 19 |
+
import argparse
|
| 20 |
+
import json
|
| 21 |
+
from collections import defaultdict
|
| 22 |
+
from pathlib import Path
|
| 23 |
+
|
| 24 |
+
LABELS = ("PER", "LOC", "ORG", "DAT")
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def load(path):
|
| 28 |
+
return {json.loads(line)["id"]: json.loads(line) for line in Path(path).open(encoding="utf8")}
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def span_set(spans):
|
| 32 |
+
return {(s["start"], s["end"], s["label"]) for s in spans}
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def prf(tp, fp, fn):
|
| 36 |
+
p = tp / (tp + fp) if tp + fp else 0.0
|
| 37 |
+
r = tp / (tp + fn) if tp + fn else 0.0
|
| 38 |
+
f = 2 * p * r / (p + r) if p + r else 0.0
|
| 39 |
+
return {"tp": tp, "fp": fp, "fn": fn, "p": round(p, 4), "r": round(r, 4), "f": round(f, 4)}
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def score(pairs):
|
| 43 |
+
"""pairs: [(ref_spans, hyp_spans)] -> {label: prf, micro: prf}."""
|
| 44 |
+
tp = defaultdict(int)
|
| 45 |
+
fp = defaultdict(int)
|
| 46 |
+
fn = defaultdict(int)
|
| 47 |
+
for ref, hyp in pairs:
|
| 48 |
+
for s in hyp & ref:
|
| 49 |
+
tp[s[2]] += 1
|
| 50 |
+
for s in hyp - ref:
|
| 51 |
+
fp[s[2]] += 1
|
| 52 |
+
for s in ref - hyp:
|
| 53 |
+
fn[s[2]] += 1
|
| 54 |
+
out = {lab: prf(tp[lab], fp[lab], fn[lab]) for lab in LABELS}
|
| 55 |
+
out["micro"] = prf(sum(tp.values()), sum(fp.values()), sum(fn.values()))
|
| 56 |
+
return out
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def render(tokens, spans):
|
| 60 |
+
return [f"[{' '.join(tokens[s['start']:s['end']])}]({s['label']})"
|
| 61 |
+
for s in sorted(spans, key=lambda s: s["start"])]
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def main():
|
| 65 |
+
ap = argparse.ArgumentParser(description=__doc__)
|
| 66 |
+
ap.add_argument("--llm", required=True)
|
| 67 |
+
ap.add_argument("--ref", required=True)
|
| 68 |
+
ap.add_argument("--out", required=True)
|
| 69 |
+
ap.add_argument("--self", dest="self_path", default=None)
|
| 70 |
+
args = ap.parse_args()
|
| 71 |
+
|
| 72 |
+
llm, ref = load(args.llm), load(args.ref)
|
| 73 |
+
missing_ids = sorted(set(ref) - set(llm), key=lambda i: int(i.split(":")[1]))
|
| 74 |
+
|
| 75 |
+
pairs, disagreements, expected = [], [], 0
|
| 76 |
+
for sid, r in sorted(ref.items(), key=lambda kv: int(kv[0].split(":")[1])):
|
| 77 |
+
h = llm.get(sid)
|
| 78 |
+
if h is None:
|
| 79 |
+
continue
|
| 80 |
+
tokens = r["tokens"]
|
| 81 |
+
rs, hs = span_set(r["silver"]), span_set(h["entities"])
|
| 82 |
+
pairs.append((rs, hs))
|
| 83 |
+
artefacts = [s for s in r["silver"] if tokens[s["end"] - 1] in ("(", ")")]
|
| 84 |
+
expected += len(artefacts)
|
| 85 |
+
if rs != hs:
|
| 86 |
+
disagreements.append({
|
| 87 |
+
"id": sid,
|
| 88 |
+
"text": r["text"],
|
| 89 |
+
"silver": render(tokens, r["silver"]),
|
| 90 |
+
"llm": render(tokens, h["entities"]),
|
| 91 |
+
"silver_paren_artefact": bool(artefacts),
|
| 92 |
+
})
|
| 93 |
+
|
| 94 |
+
result = {
|
| 95 |
+
"llm": args.llm,
|
| 96 |
+
"ref": args.ref,
|
| 97 |
+
"sentences": len(pairs),
|
| 98 |
+
"missing_ids": missing_ids,
|
| 99 |
+
"scores": score(pairs),
|
| 100 |
+
"expected_corrections": {
|
| 101 |
+
"rule": "10 (silver span ending on a parenthesis token)",
|
| 102 |
+
"spans": expected,
|
| 103 |
+
"sentences": sum(1 for d in disagreements if d["silver_paren_artefact"]),
|
| 104 |
+
},
|
| 105 |
+
"disagreements": disagreements,
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
if args.self_path:
|
| 109 |
+
other = load(args.self_path)
|
| 110 |
+
shared = sorted(set(other) & set(llm), key=lambda i: int(i.split(":")[1]))
|
| 111 |
+
sp = [(span_set(other[i]["entities"]), span_set(llm[i]["entities"])) for i in shared]
|
| 112 |
+
result["self_agreement"] = {
|
| 113 |
+
"against": args.self_path,
|
| 114 |
+
"sentences": len(shared),
|
| 115 |
+
"identical_sentences": sum(1 for a, b in sp if a == b),
|
| 116 |
+
"scores": score(sp),
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
Path(args.out).parent.mkdir(parents=True, exist_ok=True)
|
| 120 |
+
Path(args.out).write_text(json.dumps(result, ensure_ascii=False, indent=2), encoding="utf8")
|
| 121 |
+
|
| 122 |
+
m = result["scores"]["micro"]
|
| 123 |
+
print(f"sentences={result['sentences']} micro p={m['p']} r={m['r']} f={m['f']} "
|
| 124 |
+
f"(tp={m['tp']} fp={m['fp']} fn={m['fn']})")
|
| 125 |
+
for lab in LABELS:
|
| 126 |
+
s = result["scores"][lab]
|
| 127 |
+
print(f" {lab}: p={s['p']} r={s['r']} f={s['f']} (tp={s['tp']} fp={s['fp']} fn={s['fn']})")
|
| 128 |
+
print(f"disagreeing sentences={len(disagreements)} "
|
| 129 |
+
f"expected_corrections={result['expected_corrections']['spans']} spans -> {args.out}")
|
| 130 |
+
if "self_agreement" in result:
|
| 131 |
+
sa = result["self_agreement"]
|
| 132 |
+
print(f"self_agreement: {sa['identical_sentences']}/{sa['sentences']} sentences identical, "
|
| 133 |
+
f"micro f={sa['scores']['micro']['f']}")
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
if __name__ == "__main__":
|
| 137 |
+
main()
|
annotation/scripts/export_iob.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
"""Assemble the LLM annotations into a drop-in replacement for corpus/perdt-ner-iob.
|
| 3 |
+
|
| 4 |
+
python scripts/annotation/export_iob.py
|
| 5 |
+
|
| 6 |
+
Writes two-column IOB2 (`token\\tTAG`, blank line between sentences) in the exact sentence
|
| 7 |
+
order and tokenization of the source corpus, so the result can be swapped into project.yml's
|
| 8 |
+
`spacy convert` step by changing one path:
|
| 9 |
+
|
| 10 |
+
corpus/perdt-ner-iob-llm/{train,dev,test}.txt
|
| 11 |
+
|
| 12 |
+
Sentence order and token strings are asserted against corpus/perdt-ner-iob, so a partial or
|
| 13 |
+
misaligned annotation set fails loudly instead of silently training on shifted labels. The
|
| 14 |
+
output lives under corpus/ because it is a build artifact regenerable from the committed
|
| 15 |
+
JSONL in annotation/data/llm/.
|
| 16 |
+
"""
|
| 17 |
+
|
| 18 |
+
import argparse
|
| 19 |
+
import json
|
| 20 |
+
from pathlib import Path
|
| 21 |
+
|
| 22 |
+
SOURCES = {
|
| 23 |
+
"train": [f"train/shard-{i:03d}" for i in range(14)],
|
| 24 |
+
"dev": ["dev-all"],
|
| 25 |
+
"test": ["test-all"],
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def iob_sents(path):
|
| 30 |
+
sents, cur = [], []
|
| 31 |
+
for line in path.open(encoding="utf8"):
|
| 32 |
+
line = line.rstrip("\n")
|
| 33 |
+
if not line.strip():
|
| 34 |
+
if cur:
|
| 35 |
+
sents.append(cur)
|
| 36 |
+
cur = []
|
| 37 |
+
continue
|
| 38 |
+
parts = line.split("\t") if "\t" in line else line.split()
|
| 39 |
+
cur.append(parts[0])
|
| 40 |
+
if cur:
|
| 41 |
+
sents.append(cur)
|
| 42 |
+
return sents
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def tag(tokens, entities):
|
| 46 |
+
tags = ["O"] * len(tokens)
|
| 47 |
+
for e in entities:
|
| 48 |
+
tags[e["start"]] = f"B-{e['label']}"
|
| 49 |
+
for i in range(e["start"] + 1, e["end"]):
|
| 50 |
+
tags[i] = f"I-{e['label']}"
|
| 51 |
+
return tags
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def main():
|
| 55 |
+
ap = argparse.ArgumentParser(description=__doc__)
|
| 56 |
+
ap.add_argument("--llm-dir", default="annotation/data/llm/ner-v2.2-default")
|
| 57 |
+
ap.add_argument("--reference", default="corpus/perdt-ner-iob")
|
| 58 |
+
ap.add_argument("--out-dir", default="corpus/perdt-ner-iob-llm")
|
| 59 |
+
args = ap.parse_args()
|
| 60 |
+
|
| 61 |
+
out_dir = Path(args.out_dir)
|
| 62 |
+
out_dir.mkdir(parents=True, exist_ok=True)
|
| 63 |
+
|
| 64 |
+
for split, parts in SOURCES.items():
|
| 65 |
+
rows = []
|
| 66 |
+
for part in parts:
|
| 67 |
+
path = Path(args.llm_dir) / f"{part}.jsonl"
|
| 68 |
+
rows += [json.loads(line) for line in path.open(encoding="utf8")]
|
| 69 |
+
|
| 70 |
+
ref = iob_sents(Path(args.reference) / f"{split}.txt")
|
| 71 |
+
if len(rows) != len(ref):
|
| 72 |
+
raise SystemExit(f"{split}: {len(rows)} annotated sentences against {len(ref)} in corpus")
|
| 73 |
+
for i, (row, tokens) in enumerate(zip(rows, ref)):
|
| 74 |
+
if row["tokens"] != tokens:
|
| 75 |
+
raise SystemExit(f"{split}: token mismatch at sentence {i} ({row['id']})")
|
| 76 |
+
|
| 77 |
+
blocks, spans, unannotated = [], 0, 0
|
| 78 |
+
for row in rows:
|
| 79 |
+
spans += len(row["entities"])
|
| 80 |
+
unannotated += 1 if row.get("error") == "missing" else 0
|
| 81 |
+
tags = tag(row["tokens"], row["entities"])
|
| 82 |
+
blocks.append("\n".join(f"{t}\t{g}" for t, g in zip(row["tokens"], tags)))
|
| 83 |
+
# trailing blank line, matching corpus/perdt-ner-iob byte for byte in column 1
|
| 84 |
+
(out_dir / f"{split}.txt").write_text("\n\n".join(blocks) + "\n\n", encoding="utf8")
|
| 85 |
+
print(f"{split}.txt: {len(rows)} sentences, {spans} entities, "
|
| 86 |
+
f"{unannotated} unannotated -> {out_dir / f'{split}.txt'}")
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
if __name__ == "__main__":
|
| 90 |
+
main()
|
annotation/scripts/sample_gold.py
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
"""Draw a stratified, blind 200-sentence sample for human gold annotation.
|
| 3 |
+
|
| 4 |
+
python scripts/annotation/sample_gold.py
|
| 5 |
+
|
| 6 |
+
Nothing in this repo has been measured against a human. Every quality claim — the LLM
|
| 7 |
+
annotations at ~0.94 adjudicated precision, the silver layer at ~0.84, the 16% silver error
|
| 8 |
+
rate — rests on an LLM judge from the annotator's own model family, and recall is unmeasured
|
| 9 |
+
for both sides because entities *both* miss are invisible to a pairwise comparison. This
|
| 10 |
+
sample is what closes that gap.
|
| 11 |
+
|
| 12 |
+
Stratification, over the test split (1,455 sentences), because that is where every published
|
| 13 |
+
score is computed:
|
| 14 |
+
|
| 15 |
+
agree-empty silver and the LLM both find nothing -> the only stratum that can expose
|
| 16 |
+
entities both annotators miss
|
| 17 |
+
agree-spans both find exactly the same spans -> measures the agreed mass, which
|
| 18 |
+
a disagreement-only sample would
|
| 19 |
+
wrongly assume correct
|
| 20 |
+
disagree any difference at all -> the contested spans, oversampled
|
| 21 |
+
|
| 22 |
+
Strata are sampled at different rates on purpose, so estimates MUST be reweighted back to
|
| 23 |
+
the split; score_gold.py does this and prints both the raw and reweighted figures.
|
| 24 |
+
|
| 25 |
+
Writes, under annotation/human/:
|
| 26 |
+
gold-200.iob blind worksheet, every tag pre-filled O, this is what a human edits
|
| 27 |
+
gold-200.jsonl the same sentences as JSON, ids and tokens only
|
| 28 |
+
gold-200.key.jsonl silver spans, LLM spans and stratum — DO NOT OPEN before annotating
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
import argparse
|
| 32 |
+
import json
|
| 33 |
+
import random
|
| 34 |
+
from pathlib import Path
|
| 35 |
+
|
| 36 |
+
STRATA = (("agree-empty", 30), ("agree-spans", 50), ("disagree", 120))
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def load(path):
|
| 40 |
+
return {json.loads(l)["id"]: json.loads(l) for l in Path(path).open(encoding="utf8")}
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def spans_of(entities):
|
| 44 |
+
return {(e["start"], e["end"], e["label"]) for e in entities}
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def to_iob(tokens, entities):
|
| 48 |
+
tags = ["O"] * len(tokens)
|
| 49 |
+
for e in entities:
|
| 50 |
+
tags[e["start"]] = f"B-{e['label']}"
|
| 51 |
+
for i in range(e["start"] + 1, e["end"]):
|
| 52 |
+
tags[i] = f"I-{e['label']}"
|
| 53 |
+
return tags
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def main():
|
| 57 |
+
ap = argparse.ArgumentParser(description=__doc__)
|
| 58 |
+
ap.add_argument("--ref", default="annotation/data/test-all.jsonl")
|
| 59 |
+
ap.add_argument("--llm", default="annotation/data/llm/ner-v2.2-default/test-all.jsonl")
|
| 60 |
+
ap.add_argument("--out-dir", default="annotation/human")
|
| 61 |
+
ap.add_argument("--name", default="gold-200")
|
| 62 |
+
ap.add_argument("--seed", type=int, default=0)
|
| 63 |
+
args = ap.parse_args()
|
| 64 |
+
|
| 65 |
+
ref, llm = load(args.ref), load(args.llm)
|
| 66 |
+
pools = {name: [] for name, _ in STRATA}
|
| 67 |
+
for sid in sorted(ref, key=lambda s: int(s.split(":")[1])):
|
| 68 |
+
silver = spans_of(ref[sid]["silver"])
|
| 69 |
+
hyp = spans_of(llm[sid]["entities"])
|
| 70 |
+
if silver == hyp:
|
| 71 |
+
pools["agree-empty" if not silver else "agree-spans"].append(sid)
|
| 72 |
+
else:
|
| 73 |
+
pools["disagree"].append(sid)
|
| 74 |
+
|
| 75 |
+
rng = random.Random(args.seed)
|
| 76 |
+
picked = []
|
| 77 |
+
for name, n in STRATA:
|
| 78 |
+
pool = pools[name]
|
| 79 |
+
if len(pool) < n:
|
| 80 |
+
raise SystemExit(f"stratum {name} has {len(pool)} sentences, need {n}")
|
| 81 |
+
picked += [(sid, name, len(pool)) for sid in rng.sample(pool, n)]
|
| 82 |
+
rng.shuffle(picked) # so the annotator cannot read strata off the ordering
|
| 83 |
+
|
| 84 |
+
out = Path(args.out_dir)
|
| 85 |
+
out.mkdir(parents=True, exist_ok=True)
|
| 86 |
+
blocks, blind, key = [], [], []
|
| 87 |
+
silver_blocks, llm_blocks, review_blocks = [], [], []
|
| 88 |
+
n_marked = 0
|
| 89 |
+
for sid, stratum, pool_size in picked:
|
| 90 |
+
tokens = ref[sid]["tokens"]
|
| 91 |
+
s_tags = to_iob(tokens, ref[sid]["silver"])
|
| 92 |
+
l_tags = to_iob(tokens, llm[sid]["entities"])
|
| 93 |
+
head = f"# {sid}"
|
| 94 |
+
blocks.append(head + "\n" + "\n".join(f"{t}\tO" for t in tokens))
|
| 95 |
+
silver_blocks.append(head + "\n" + "\n".join(f"{t}\t{g}" for t, g in zip(tokens, s_tags)))
|
| 96 |
+
llm_blocks.append(head + "\n" + "\n".join(f"{t}\t{g}" for t, g in zip(tokens, l_tags)))
|
| 97 |
+
# Review sheet: both annotators side by side, a verdict column seeded with the LLM
|
| 98 |
+
# tag, and a marker on every token where they differ so the eye goes straight there.
|
| 99 |
+
rows = []
|
| 100 |
+
for t, s, l in zip(tokens, s_tags, l_tags):
|
| 101 |
+
mark = "" if s == l else "\t*"
|
| 102 |
+
n_marked += s != l
|
| 103 |
+
rows.append(f"{t}\t{s}\t{l}\t{l}{mark}")
|
| 104 |
+
review_blocks.append(head + "\n" + "\n".join(rows))
|
| 105 |
+
blind.append({"id": sid, "tokens": tokens, "text": ref[sid]["text"], "entities": []})
|
| 106 |
+
key.append({
|
| 107 |
+
"id": sid,
|
| 108 |
+
"stratum": stratum,
|
| 109 |
+
"stratum_size": pool_size,
|
| 110 |
+
"stratum_sampled": dict(STRATA)[stratum],
|
| 111 |
+
"tokens": tokens,
|
| 112 |
+
"silver": ref[sid]["silver"],
|
| 113 |
+
"llm": llm[sid]["entities"],
|
| 114 |
+
})
|
| 115 |
+
for fname, rows in ((f"{args.name}.jsonl", blind), (f"{args.name}.key.jsonl", key)):
|
| 116 |
+
with (out / fname).open("w", encoding="utf8") as fh:
|
| 117 |
+
for row in rows:
|
| 118 |
+
fh.write(json.dumps(row, ensure_ascii=False) + "\n")
|
| 119 |
+
for fname, bs in ((f"{args.name}.iob", blocks),
|
| 120 |
+
(f"{args.name}.silver.iob", silver_blocks),
|
| 121 |
+
(f"{args.name}.llm.iob", llm_blocks),
|
| 122 |
+
(f"{args.name}.review.tsv", review_blocks)):
|
| 123 |
+
(out / fname).write_text("\n\n".join(bs) + "\n\n", encoding="utf8")
|
| 124 |
+
|
| 125 |
+
tokens = sum(len(ref[sid]["tokens"]) for sid, _, _ in picked)
|
| 126 |
+
print(f"{len(picked)} sentences, {tokens} tokens")
|
| 127 |
+
for name, n in STRATA:
|
| 128 |
+
print(f" {name}: {n} sampled of {len(pools[name])} in the split "
|
| 129 |
+
f"(weight {len(pools[name]) / n:.2f})")
|
| 130 |
+
print(f" {out}/{args.name}.iob blind worksheet, all tags O")
|
| 131 |
+
print(f" {out}/{args.name}.silver.iob pre-filled with the silver layer, for review")
|
| 132 |
+
print(f" {out}/{args.name}.llm.iob pre-filled with the LLM annotation, for review")
|
| 133 |
+
print(f" {out}/{args.name}.review.tsv token, silver, llm, verdict; {n_marked} tokens "
|
| 134 |
+
f"marked * where the two differ")
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
if __name__ == "__main__":
|
| 138 |
+
main()
|
annotation/scripts/score_gold.py
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
"""Score the silver layer and the LLM annotations against human gold.
|
| 3 |
+
|
| 4 |
+
python scripts/annotation/score_gold.py --gold annotation/human/gold-200.iob
|
| 5 |
+
|
| 6 |
+
Reads the completed worksheet (the `O` column edited by hand), joins it to
|
| 7 |
+
gold-200.key.jsonl, and reports precision/recall/F for BOTH annotators against the human,
|
| 8 |
+
per label and overall.
|
| 9 |
+
|
| 10 |
+
Two things this does that a naive script would get wrong:
|
| 11 |
+
|
| 12 |
+
1. **Reweighting.** The sample is stratified with deliberately unequal rates — 30 of 916
|
| 13 |
+
agree-empty sentences, 120 of 229 disagreeing ones. Raw sample counts therefore describe
|
| 14 |
+
the sample, not the split. Each sentence carries weight `stratum_size / stratum_sampled`,
|
| 15 |
+
and the reweighted figures are the ones that generalise to the 1,455-sentence test split.
|
| 16 |
+
Both are printed; they differ a lot, and the raw numbers are the misleading ones.
|
| 17 |
+
2. **`--judge`.** Given the adjudication dump that produced the ~0.94 precision estimate,
|
| 18 |
+
it also scores the LLM judge's verdicts against the human, which is the only way to learn
|
| 19 |
+
whether the judge's bias toward its own family was real and how large it was.
|
| 20 |
+
|
| 21 |
+
With `--second <file>` it reports inter-annotator agreement between two human worksheets
|
| 22 |
+
instead, which is the number that says whether the guideline is teachable at all.
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
import argparse
|
| 26 |
+
import json
|
| 27 |
+
from collections import defaultdict
|
| 28 |
+
from pathlib import Path
|
| 29 |
+
|
| 30 |
+
LABELS = ("PER", "LOC", "ORG", "DAT")
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def read_worksheet(path, column=2):
|
| 34 |
+
"""-> {id: [(start, end, label)]}, driven by the `# <id>` header before each block.
|
| 35 |
+
|
| 36 |
+
`column` is 1-based: 2 for the two-column worksheets, 4 for the verdict column of
|
| 37 |
+
gold-200.review.tsv (token, silver, llm, verdict).
|
| 38 |
+
"""
|
| 39 |
+
out, sid, tags = {}, None, []
|
| 40 |
+
for line in Path(path).open(encoding="utf8"):
|
| 41 |
+
line = line.rstrip("\n")
|
| 42 |
+
if line.startswith("# "):
|
| 43 |
+
sid, tags = line[2:].strip(), []
|
| 44 |
+
continue
|
| 45 |
+
if not line.strip():
|
| 46 |
+
if sid is not None and tags:
|
| 47 |
+
out[sid] = spans_from_iob(tags)
|
| 48 |
+
sid, tags = None, []
|
| 49 |
+
continue
|
| 50 |
+
parts = line.split("\t")
|
| 51 |
+
if len(parts) < column:
|
| 52 |
+
raise SystemExit(f"{path}: line {line!r} has {len(parts)} columns, need {column}")
|
| 53 |
+
tags.append(parts[column - 1].strip())
|
| 54 |
+
if sid is not None and tags:
|
| 55 |
+
out[sid] = spans_from_iob(tags)
|
| 56 |
+
return out
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def spans_from_iob(tags):
|
| 60 |
+
spans, i = [], 0
|
| 61 |
+
while i < len(tags):
|
| 62 |
+
if tags[i].startswith("B-"):
|
| 63 |
+
label, j = tags[i][2:], i + 1
|
| 64 |
+
while j < len(tags) and tags[j] == f"I-{label}":
|
| 65 |
+
j += 1
|
| 66 |
+
spans.append((i, j, label))
|
| 67 |
+
i = j
|
| 68 |
+
else:
|
| 69 |
+
if tags[i] not in ("O", "") and not tags[i].startswith("I-"):
|
| 70 |
+
raise SystemExit(f"unknown tag {tags[i]!r}")
|
| 71 |
+
i += 1
|
| 72 |
+
return spans
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def prf(tp, fp, fn):
|
| 76 |
+
p = tp / (tp + fp) if tp + fp else 0.0
|
| 77 |
+
r = tp / (tp + fn) if tp + fn else 0.0
|
| 78 |
+
return p, r, (2 * p * r / (p + r) if p + r else 0.0)
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def report(title, counts):
|
| 82 |
+
print(f"\n== {title}")
|
| 83 |
+
tp = sum(c[0] for c in counts.values())
|
| 84 |
+
fp = sum(c[1] for c in counts.values())
|
| 85 |
+
fn = sum(c[2] for c in counts.values())
|
| 86 |
+
p, r, f = prf(tp, fp, fn)
|
| 87 |
+
print(f" micro p={p:.3f} r={r:.3f} f={f:.3f} (tp={tp:.1f} fp={fp:.1f} fn={fn:.1f})")
|
| 88 |
+
for lab in LABELS:
|
| 89 |
+
t, fp_, fn_ = counts[lab]
|
| 90 |
+
if t + fp_ + fn_ == 0:
|
| 91 |
+
continue
|
| 92 |
+
p, r, f = prf(t, fp_, fn_)
|
| 93 |
+
print(f" {lab}: p={p:.3f} r={r:.3f} f={f:.3f}")
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def score(gold, systems, weights):
|
| 97 |
+
"""-> {system: (raw counts, weighted counts)} keyed by label."""
|
| 98 |
+
out = {}
|
| 99 |
+
for name, sysspans in systems.items():
|
| 100 |
+
raw = defaultdict(lambda: [0.0, 0.0, 0.0])
|
| 101 |
+
wtd = defaultdict(lambda: [0.0, 0.0, 0.0])
|
| 102 |
+
for sid, g in gold.items():
|
| 103 |
+
h, w = set(sysspans.get(sid, [])), weights[sid]
|
| 104 |
+
g = set(g)
|
| 105 |
+
for s in h & g:
|
| 106 |
+
raw[s[2]][0] += 1; wtd[s[2]][0] += w
|
| 107 |
+
for s in h - g:
|
| 108 |
+
raw[s[2]][1] += 1; wtd[s[2]][1] += w
|
| 109 |
+
for s in g - h:
|
| 110 |
+
raw[s[2]][2] += 1; wtd[s[2]][2] += w
|
| 111 |
+
out[name] = (raw, wtd)
|
| 112 |
+
return out
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def main():
|
| 116 |
+
ap = argparse.ArgumentParser(description=__doc__)
|
| 117 |
+
ap.add_argument("--gold", default="annotation/human/gold-200.iob")
|
| 118 |
+
ap.add_argument("--key", default="annotation/human/gold-200.key.jsonl")
|
| 119 |
+
ap.add_argument("--second", help="a second annotator's worksheet, for IAA")
|
| 120 |
+
ap.add_argument("--judge", help="adjudication dump with per-span verdicts")
|
| 121 |
+
ap.add_argument("--column", type=int, default=2,
|
| 122 |
+
help="1-based tag column; use 4 for a corrected gold-200.review.tsv")
|
| 123 |
+
ap.add_argument("--check", action="store_true",
|
| 124 |
+
help="validate the worksheet's structure and exit, printing no scores")
|
| 125 |
+
args = ap.parse_args()
|
| 126 |
+
|
| 127 |
+
key = {json.loads(l)["id"]: json.loads(l) for l in Path(args.key).open(encoding="utf8")}
|
| 128 |
+
gold = read_worksheet(args.gold, args.column)
|
| 129 |
+
missing = [sid for sid in key if sid not in gold]
|
| 130 |
+
if missing:
|
| 131 |
+
raise SystemExit(f"{len(missing)} sentences are unannotated, e.g. {missing[:3]}")
|
| 132 |
+
|
| 133 |
+
if args.check:
|
| 134 |
+
extra = sorted(set(gold) - set(key))
|
| 135 |
+
if extra:
|
| 136 |
+
raise SystemExit(f"{len(extra)} unknown sentence ids, e.g. {extra[:3]}")
|
| 137 |
+
moved = [sid for sid, k in key.items()
|
| 138 |
+
if any(s[1] > len(k["tokens"]) for s in gold[sid])]
|
| 139 |
+
if moved:
|
| 140 |
+
raise SystemExit(f"spans run past the end of the sentence in {moved[:3]}")
|
| 141 |
+
spans = sum(len(v) for v in gold.values())
|
| 142 |
+
by_label = defaultdict(int)
|
| 143 |
+
for v in gold.values():
|
| 144 |
+
for s in v:
|
| 145 |
+
by_label[s[2]] += 1
|
| 146 |
+
print(f"OK — {len(gold)} sentences, {spans} spans, "
|
| 147 |
+
+ ", ".join(f"{lab} {by_label[lab]}" for lab in LABELS))
|
| 148 |
+
print("Tags parse, every sentence is present, no span runs off the end.")
|
| 149 |
+
return
|
| 150 |
+
|
| 151 |
+
if args.second:
|
| 152 |
+
other = read_worksheet(args.second, args.column)
|
| 153 |
+
shared = sorted(set(gold) & set(other))
|
| 154 |
+
counts = defaultdict(lambda: [0.0, 0.0, 0.0])
|
| 155 |
+
same = 0
|
| 156 |
+
for sid in shared:
|
| 157 |
+
a, b = set(gold[sid]), set(other[sid])
|
| 158 |
+
same += a == b
|
| 159 |
+
for s in a & b:
|
| 160 |
+
counts[s[2]][0] += 1
|
| 161 |
+
for s in b - a:
|
| 162 |
+
counts[s[2]][1] += 1
|
| 163 |
+
for s in a - b:
|
| 164 |
+
counts[s[2]][2] += 1
|
| 165 |
+
report(f"inter-annotator agreement over {len(shared)} shared sentences", counts)
|
| 166 |
+
print(f" {same}/{len(shared)} sentences annotated identically")
|
| 167 |
+
return
|
| 168 |
+
|
| 169 |
+
weights = {sid: k["stratum_size"] / k["stratum_sampled"] for sid, k in key.items()}
|
| 170 |
+
systems = {
|
| 171 |
+
"silver (PerDT)": {sid: [(s["start"], s["end"], s["label"]) for s in k["silver"]]
|
| 172 |
+
for sid, k in key.items()},
|
| 173 |
+
"LLM (v2.2)": {sid: [(e["start"], e["end"], e["label"]) for e in k["llm"]]
|
| 174 |
+
for sid, k in key.items()},
|
| 175 |
+
}
|
| 176 |
+
n_gold = sum(len(v) for v in gold.values())
|
| 177 |
+
print(f"human gold: {len(gold)} sentences, {n_gold} spans")
|
| 178 |
+
for name, (raw, wtd) in score(gold, systems, weights).items():
|
| 179 |
+
report(f"{name} against human gold — raw sample counts", raw)
|
| 180 |
+
report(f"{name} against human gold — reweighted to the test split", wtd)
|
| 181 |
+
|
| 182 |
+
if args.judge:
|
| 183 |
+
verdicts = json.load(Path(args.judge).open(encoding="utf8"))
|
| 184 |
+
agree = total = 0
|
| 185 |
+
wrong = []
|
| 186 |
+
for v in verdicts:
|
| 187 |
+
sid, kind = v["id"], v["kind"]
|
| 188 |
+
if sid not in gold or kind not in ("fp", "fn") or v["verdict"] not in ("correct", "incorrect"):
|
| 189 |
+
continue
|
| 190 |
+
tokens = key[sid]["tokens"]
|
| 191 |
+
human = {(" ".join(tokens[s[0]:s[1]]), s[2]) for s in gold[sid]}
|
| 192 |
+
# fp: a span only the LLM has. fn: a span only the silver layer has. Either way
|
| 193 |
+
# "correct" claims the span belongs, and the human worksheet settles it.
|
| 194 |
+
in_gold = (v["span"], v["label"]) in human
|
| 195 |
+
judged_correct = v["verdict"] == "correct"
|
| 196 |
+
total += 1
|
| 197 |
+
if in_gold == judged_correct:
|
| 198 |
+
agree += 1
|
| 199 |
+
else:
|
| 200 |
+
wrong.append(f"{sid} [{v['span']}]({v['label']}) {kind}: judge said "
|
| 201 |
+
f"{v['verdict']}, human {'has' if in_gold else 'lacks'} it")
|
| 202 |
+
if not total:
|
| 203 |
+
print("\n== judge review: no adjudicated spans fall inside the gold sample")
|
| 204 |
+
return
|
| 205 |
+
print(f"\n== judge review: {agree}/{total} verdicts match the human ({agree/total:.1%})")
|
| 206 |
+
print(" Every precision estimate quoted for this dataset rests on these verdicts;")
|
| 207 |
+
print(" this percentage is how much that estimate can be trusted.")
|
| 208 |
+
for line in wrong[:20]:
|
| 209 |
+
print(f" MISJUDGED {line}")
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
if __name__ == "__main__":
|
| 213 |
+
main()
|
annotation/scripts/select_sentences.py
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
"""Deterministic sentence selection for the LLM NER annotation kit.
|
| 3 |
+
|
| 4 |
+
Reads the PerDT test split in two-column IOB2 (`corpus/perdt-ner-iob/test.txt`, the
|
| 5 |
+
`--merge-subtokens` tokenization) and writes two id-sorted JSONL files:
|
| 6 |
+
|
| 7 |
+
annotation/data/pool-500.jsonl 400 entity-rich + 100 entity-free sentences
|
| 8 |
+
annotation/data/select-100.jsonl 80 rich + 20 empty, a subset of the pool
|
| 9 |
+
|
| 10 |
+
Only PER/LOC/ORG/DAT are kept as silver spans; MON/TIM/PCT are dropped (too thin to
|
| 11 |
+
annotate: 205/135/121 train spans). A sentence is "empty" only if it has no silver span
|
| 12 |
+
of any label at all, so the 8 MON/TIM/PCT-only sentences land in neither bucket.
|
| 13 |
+
|
| 14 |
+
Selection is seeded with random.Random(0) and re-runs byte-identically.
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
import argparse
|
| 18 |
+
import json
|
| 19 |
+
import random
|
| 20 |
+
from pathlib import Path
|
| 21 |
+
|
| 22 |
+
KEEP = ("PER", "LOC", "ORG", "DAT")
|
| 23 |
+
MIN_TOKENS, MAX_TOKENS = 6, 45
|
| 24 |
+
# select-100 per-label sentence minimums, applied greedily in this order
|
| 25 |
+
MINIMUMS = (("DAT", 20), ("ORG", 25), ("PER", 25), ("LOC", 25))
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def iob_sents(path):
|
| 29 |
+
"""[(tokens, tags)] — blank line separates sentences, same reader as transfer_perdt_ner."""
|
| 30 |
+
sents, cur = [], []
|
| 31 |
+
for line in path.open(encoding="utf8"):
|
| 32 |
+
line = line.rstrip("\n")
|
| 33 |
+
if not line.strip():
|
| 34 |
+
if cur:
|
| 35 |
+
sents.append(cur)
|
| 36 |
+
cur = []
|
| 37 |
+
continue
|
| 38 |
+
p = line.split("\t")
|
| 39 |
+
if len(p) < 2:
|
| 40 |
+
p = line.split()
|
| 41 |
+
if len(p) < 2:
|
| 42 |
+
continue
|
| 43 |
+
cur.append((p[0], p[-1]))
|
| 44 |
+
if cur:
|
| 45 |
+
sents.append(cur)
|
| 46 |
+
return [([t for t, _ in s], [g for _, g in s]) for s in sents]
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def spans_from_iob(tags):
|
| 50 |
+
"""[(start, end, label)] over token indices; end is exclusive."""
|
| 51 |
+
spans, i = [], 0
|
| 52 |
+
while i < len(tags):
|
| 53 |
+
tag = tags[i]
|
| 54 |
+
if tag.startswith("B-"):
|
| 55 |
+
label, j = tag[2:], i + 1
|
| 56 |
+
while j < len(tags) and tags[j] == f"I-{label}":
|
| 57 |
+
j += 1
|
| 58 |
+
spans.append((i, j, label))
|
| 59 |
+
i = j
|
| 60 |
+
else:
|
| 61 |
+
i += 1
|
| 62 |
+
return spans
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def record(split, idx, tokens, spans):
|
| 66 |
+
return {
|
| 67 |
+
"id": f"{split}:{idx}",
|
| 68 |
+
"tokens": tokens,
|
| 69 |
+
"text": " ".join(tokens),
|
| 70 |
+
"silver": [
|
| 71 |
+
{"start": s, "end": e, "label": lab, "text": " ".join(tokens[s:e])}
|
| 72 |
+
for s, e, lab in spans
|
| 73 |
+
if lab in KEEP
|
| 74 |
+
],
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def labels_of(rec):
|
| 79 |
+
return {e["label"] for e in rec["silver"]}
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def dump(path, recs):
|
| 83 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 84 |
+
with path.open("w", encoding="utf8") as fh:
|
| 85 |
+
for r in sorted(recs, key=lambda r: int(r["id"].split(":")[1])):
|
| 86 |
+
fh.write(json.dumps(r, ensure_ascii=False) + "\n")
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def report(name, recs, n_rich, n_empty):
|
| 90 |
+
print(f"{name}: {len(recs)} sentences ({n_rich} rich, {n_empty} empty)")
|
| 91 |
+
for lab in KEEP:
|
| 92 |
+
sents = sum(1 for r in recs if lab in labels_of(r))
|
| 93 |
+
spans = sum(1 for r in recs for e in r["silver"] if e["label"] == lab)
|
| 94 |
+
print(f" {lab}: {sents} sentences, {spans} spans")
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def main():
|
| 98 |
+
ap = argparse.ArgumentParser(description=__doc__)
|
| 99 |
+
ap.add_argument("--corpus", default="corpus/perdt-ner-iob/test.txt")
|
| 100 |
+
ap.add_argument("--split", default="test")
|
| 101 |
+
ap.add_argument("--out-dir", default="annotation/data")
|
| 102 |
+
ap.add_argument("--seed", type=int, default=0)
|
| 103 |
+
ap.add_argument("--mode", choices=("kit", "split"), default="kit",
|
| 104 |
+
help="kit: test-all + pool-500 + select-100; "
|
| 105 |
+
"split: the whole split as shards, for bulk relabelling")
|
| 106 |
+
ap.add_argument("--shard-size", type=int, default=2000,
|
| 107 |
+
help="sentences per shard in split mode; 0 writes one file")
|
| 108 |
+
args = ap.parse_args()
|
| 109 |
+
|
| 110 |
+
sents = iob_sents(Path(args.corpus))
|
| 111 |
+
rich, empty, every = [], [], []
|
| 112 |
+
for idx, (tokens, tags) in enumerate(sents):
|
| 113 |
+
spans = spans_from_iob(tags)
|
| 114 |
+
rec = record(args.split, idx, tokens, spans)
|
| 115 |
+
every.append(rec)
|
| 116 |
+
if not spans:
|
| 117 |
+
empty.append(rec)
|
| 118 |
+
elif rec["silver"] and MIN_TOKENS <= len(tokens) <= MAX_TOKENS:
|
| 119 |
+
rich.append(rec)
|
| 120 |
+
print(f"corpus: {len(sents)} sentences, {len(rich)} rich (after length filter), "
|
| 121 |
+
f"{len(empty)} empty")
|
| 122 |
+
|
| 123 |
+
if args.mode == "split":
|
| 124 |
+
out = Path(args.out_dir)
|
| 125 |
+
if args.shard_size:
|
| 126 |
+
shards = [every[i:i + args.shard_size] for i in range(0, len(every), args.shard_size)]
|
| 127 |
+
for n, shard in enumerate(shards):
|
| 128 |
+
dump(out / f"shard-{n:03d}.jsonl", shard)
|
| 129 |
+
where = f"{len(shards)} shards of <= {args.shard_size} sentences in {out}"
|
| 130 |
+
else:
|
| 131 |
+
dump(out / f"{args.split}-all.jsonl", every)
|
| 132 |
+
where = f"one file, {out}/{args.split}-all.jsonl"
|
| 133 |
+
n_any = sum(1 for r in every if r["silver"])
|
| 134 |
+
report(args.split, every, n_any, len(every) - n_any)
|
| 135 |
+
print(where)
|
| 136 |
+
return
|
| 137 |
+
|
| 138 |
+
rng = random.Random(args.seed)
|
| 139 |
+
|
| 140 |
+
# --- pool: 400 rich, seeded with every DAT and every ORG sentence, then a shuffled fill
|
| 141 |
+
chosen = {r["id"] for r in rich if "DAT" in labels_of(r)}
|
| 142 |
+
chosen |= {r["id"] for r in rich if "ORG" in labels_of(r)}
|
| 143 |
+
pool_rich = [r for r in rich if r["id"] in chosen]
|
| 144 |
+
if len(pool_rich) > 400:
|
| 145 |
+
raise SystemExit(f"DAT+ORG seed is {len(pool_rich)} sentences, over the 400 budget")
|
| 146 |
+
remainder = [r for r in rich if r["id"] not in chosen]
|
| 147 |
+
rng.shuffle(remainder)
|
| 148 |
+
pool_rich += remainder[: 400 - len(pool_rich)]
|
| 149 |
+
|
| 150 |
+
pool_empty = list(empty)
|
| 151 |
+
rng.shuffle(pool_empty)
|
| 152 |
+
pool_empty = pool_empty[:100]
|
| 153 |
+
pool = pool_rich + pool_empty
|
| 154 |
+
|
| 155 |
+
# --- select-100: 80 rich meeting per-label minimums, 20 empty
|
| 156 |
+
order = list(pool_rich)
|
| 157 |
+
rng.shuffle(order)
|
| 158 |
+
picked, picked_ids = [], set()
|
| 159 |
+
|
| 160 |
+
def take(rec):
|
| 161 |
+
picked.append(rec)
|
| 162 |
+
picked_ids.add(rec["id"])
|
| 163 |
+
|
| 164 |
+
for label, minimum in MINIMUMS:
|
| 165 |
+
have = sum(1 for r in picked if label in labels_of(r))
|
| 166 |
+
for r in order:
|
| 167 |
+
if have >= minimum:
|
| 168 |
+
break
|
| 169 |
+
if r["id"] in picked_ids or label not in labels_of(r):
|
| 170 |
+
continue
|
| 171 |
+
take(r)
|
| 172 |
+
have += 1
|
| 173 |
+
if have < minimum:
|
| 174 |
+
raise SystemExit(f"cannot reach {label} >= {minimum}: only {have} available")
|
| 175 |
+
for r in order:
|
| 176 |
+
if len(picked) >= 80:
|
| 177 |
+
break
|
| 178 |
+
if r["id"] not in picked_ids:
|
| 179 |
+
take(r)
|
| 180 |
+
|
| 181 |
+
sel_empty = list(pool_empty)
|
| 182 |
+
rng.shuffle(sel_empty)
|
| 183 |
+
sel_empty = sel_empty[:20]
|
| 184 |
+
select = picked + sel_empty
|
| 185 |
+
|
| 186 |
+
out = Path(args.out_dir)
|
| 187 |
+
dump(out / "test-all.jsonl", every)
|
| 188 |
+
dump(out / "pool-500.jsonl", pool)
|
| 189 |
+
dump(out / "select-100.jsonl", select)
|
| 190 |
+
n_any = sum(1 for r in every if r["silver"])
|
| 191 |
+
report("test-all", every, n_any, len(every) - n_any)
|
| 192 |
+
report("pool-500", pool, len(pool_rich), len(pool_empty))
|
| 193 |
+
report("select-100", select, len(picked), len(sel_empty))
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
if __name__ == "__main__":
|
| 197 |
+
main()
|
annotation/scripts/validate_responses.py
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
"""Validate raw LLM NER responses and align entity strings back to corpus tokens.
|
| 3 |
+
|
| 4 |
+
python scripts/annotation/validate_responses.py \
|
| 5 |
+
--input annotation/data/select-100.jsonl \
|
| 6 |
+
--responses annotation/work/responses/select-100.jsonl \
|
| 7 |
+
--out-dir annotation/data/llm/ner-v1-default --name select-100
|
| 8 |
+
|
| 9 |
+
An entity is accepted only if its text reproduces a consecutive token subsequence of the
|
| 10 |
+
sentence. Search runs forward from the previously accepted entity's end (entities come in
|
| 11 |
+
sentence order, which disambiguates repeat mentions); if that fails, any non-overlapping
|
| 12 |
+
occurrence is accepted, and an entity that can only land on already-taken tokens is dropped
|
| 13 |
+
as `overlap`. Everything dropped is written to <name>.invalid.jsonl with its reason.
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
+
import argparse
|
| 17 |
+
import json
|
| 18 |
+
from pathlib import Path
|
| 19 |
+
|
| 20 |
+
LABELS = ("PER", "LOC", "ORG", "DAT")
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def load_jsonl(path):
|
| 24 |
+
return [json.loads(line) for line in Path(path).open(encoding="utf8")]
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def occurrences(tokens, parts):
|
| 28 |
+
"""Start indices where `parts` appears as a consecutive token subsequence."""
|
| 29 |
+
n, m = len(tokens), len(parts)
|
| 30 |
+
if m == 0 or m > n:
|
| 31 |
+
return []
|
| 32 |
+
return [i for i in range(n - m + 1) if tokens[i : i + m] == parts]
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def align(tokens, entities):
|
| 36 |
+
"""-> (accepted spans, dropped [(text, label, reason)])."""
|
| 37 |
+
accepted, dropped, cursor = [], [], 0
|
| 38 |
+
taken = set()
|
| 39 |
+
for ent in entities:
|
| 40 |
+
text = (ent.get("text") or "").strip()
|
| 41 |
+
label = ent.get("label")
|
| 42 |
+
if label not in LABELS:
|
| 43 |
+
dropped.append((text, label, "bad-label"))
|
| 44 |
+
continue
|
| 45 |
+
parts = text.split()
|
| 46 |
+
starts = occurrences(tokens, parts)
|
| 47 |
+
if not starts:
|
| 48 |
+
dropped.append((text, label, "no-align"))
|
| 49 |
+
continue
|
| 50 |
+
free = [s for s in starts if not (taken & set(range(s, s + len(parts))))]
|
| 51 |
+
if not free:
|
| 52 |
+
dropped.append((text, label, "overlap"))
|
| 53 |
+
continue
|
| 54 |
+
forward = [s for s in free if s >= cursor]
|
| 55 |
+
start = forward[0] if forward else free[0]
|
| 56 |
+
end = start + len(parts)
|
| 57 |
+
accepted.append({"start": start, "end": end, "label": label, "text": " ".join(parts)})
|
| 58 |
+
taken |= set(range(start, end))
|
| 59 |
+
cursor = end
|
| 60 |
+
accepted.sort(key=lambda s: s["start"])
|
| 61 |
+
return accepted, dropped
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def to_iob(tokens, spans):
|
| 65 |
+
tags = ["O"] * len(tokens)
|
| 66 |
+
for s in spans:
|
| 67 |
+
tags[s["start"]] = f"B-{s['label']}"
|
| 68 |
+
for i in range(s["start"] + 1, s["end"]):
|
| 69 |
+
tags[i] = f"I-{s['label']}"
|
| 70 |
+
return tags
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def main():
|
| 74 |
+
ap = argparse.ArgumentParser(description=__doc__)
|
| 75 |
+
ap.add_argument("--input", required=True)
|
| 76 |
+
ap.add_argument("--responses", required=True)
|
| 77 |
+
ap.add_argument("--out-dir", required=True)
|
| 78 |
+
ap.add_argument("--name", required=True)
|
| 79 |
+
args = ap.parse_args()
|
| 80 |
+
|
| 81 |
+
sents = load_jsonl(args.input)
|
| 82 |
+
responses = load_jsonl(args.responses)
|
| 83 |
+
|
| 84 |
+
items, dupes = {}, 0
|
| 85 |
+
model = prompt_hash = None
|
| 86 |
+
for resp in responses:
|
| 87 |
+
model = resp.get("model", model)
|
| 88 |
+
prompt_hash = resp.get("prompt_hash", prompt_hash)
|
| 89 |
+
for item in resp.get("items", []):
|
| 90 |
+
if item["id"] in items:
|
| 91 |
+
dupes += 1
|
| 92 |
+
continue
|
| 93 |
+
items[item["id"]] = item
|
| 94 |
+
|
| 95 |
+
out_dir = Path(args.out_dir)
|
| 96 |
+
out_dir.mkdir(parents=True, exist_ok=True)
|
| 97 |
+
counts = {"no-align": 0, "bad-label": 0, "overlap": 0}
|
| 98 |
+
n_ent = missing = 0
|
| 99 |
+
rows, iob_blocks, invalid = [], [], []
|
| 100 |
+
|
| 101 |
+
for sent in sents:
|
| 102 |
+
item = items.get(sent["id"])
|
| 103 |
+
if item is None:
|
| 104 |
+
missing += 1
|
| 105 |
+
spans = []
|
| 106 |
+
else:
|
| 107 |
+
spans, dropped = align(sent["tokens"], item.get("entities", []))
|
| 108 |
+
for text, label, reason in dropped:
|
| 109 |
+
counts[reason] += 1
|
| 110 |
+
invalid.append({"id": sent["id"], "text": text, "label": label, "reason": reason})
|
| 111 |
+
n_ent += len(spans)
|
| 112 |
+
row = {
|
| 113 |
+
"id": sent["id"],
|
| 114 |
+
"tokens": sent["tokens"],
|
| 115 |
+
"entities": spans,
|
| 116 |
+
"model": model,
|
| 117 |
+
"prompt_hash": prompt_hash,
|
| 118 |
+
}
|
| 119 |
+
if item is None:
|
| 120 |
+
row["error"] = "missing"
|
| 121 |
+
rows.append(row)
|
| 122 |
+
tags = to_iob(sent["tokens"], spans)
|
| 123 |
+
iob_blocks.append("\n".join(f"{t}\t{g}" for t, g in zip(sent["tokens"], tags)))
|
| 124 |
+
|
| 125 |
+
with (out_dir / f"{args.name}.jsonl").open("w", encoding="utf8") as fh:
|
| 126 |
+
for row in rows:
|
| 127 |
+
fh.write(json.dumps(row, ensure_ascii=False) + "\n")
|
| 128 |
+
(out_dir / f"{args.name}.iob").write_text("\n\n".join(iob_blocks) + "\n", encoding="utf8")
|
| 129 |
+
with (out_dir / f"{args.name}.invalid.jsonl").open("w", encoding="utf8") as fh:
|
| 130 |
+
for row in invalid:
|
| 131 |
+
fh.write(json.dumps(row, ensure_ascii=False) + "\n")
|
| 132 |
+
|
| 133 |
+
dropped_total = sum(counts.values())
|
| 134 |
+
print(f"sentences={len(rows)} entities={n_ent} dropped={dropped_total} "
|
| 135 |
+
f"(no-align={counts['no-align']} bad-label={counts['bad-label']} "
|
| 136 |
+
f"overlap={counts['overlap']}) missing={missing} duplicate_items={dupes}")
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
if __name__ == "__main__":
|
| 140 |
+
main()
|
llm/agreement.json
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"reference": "silver, restricted to PER/LOC/ORG/DAT",
|
| 3 |
+
"hypothesis": "llm",
|
| 4 |
+
"match": "exact span (start, end, label)",
|
| 5 |
+
"splits": {
|
| 6 |
+
"train": {
|
| 7 |
+
"PER": {
|
| 8 |
+
"tp": 3443,
|
| 9 |
+
"fp": 1328,
|
| 10 |
+
"fn": 1404,
|
| 11 |
+
"p": 0.7217,
|
| 12 |
+
"r": 0.7103,
|
| 13 |
+
"f": 0.7159
|
| 14 |
+
},
|
| 15 |
+
"LOC": {
|
| 16 |
+
"tp": 4063,
|
| 17 |
+
"fp": 948,
|
| 18 |
+
"fn": 891,
|
| 19 |
+
"p": 0.8108,
|
| 20 |
+
"r": 0.8201,
|
| 21 |
+
"f": 0.8155
|
| 22 |
+
},
|
| 23 |
+
"ORG": {
|
| 24 |
+
"tp": 1661,
|
| 25 |
+
"fp": 617,
|
| 26 |
+
"fn": 982,
|
| 27 |
+
"p": 0.7291,
|
| 28 |
+
"r": 0.6285,
|
| 29 |
+
"f": 0.6751
|
| 30 |
+
},
|
| 31 |
+
"DAT": {
|
| 32 |
+
"tp": 1006,
|
| 33 |
+
"fp": 578,
|
| 34 |
+
"fn": 317,
|
| 35 |
+
"p": 0.6351,
|
| 36 |
+
"r": 0.7604,
|
| 37 |
+
"f": 0.6921
|
| 38 |
+
},
|
| 39 |
+
"micro": {
|
| 40 |
+
"tp": 10173,
|
| 41 |
+
"fp": 3471,
|
| 42 |
+
"fn": 3594,
|
| 43 |
+
"p": 0.7456,
|
| 44 |
+
"r": 0.7389,
|
| 45 |
+
"f": 0.7423
|
| 46 |
+
}
|
| 47 |
+
},
|
| 48 |
+
"dev": {
|
| 49 |
+
"PER": {
|
| 50 |
+
"tp": 183,
|
| 51 |
+
"fp": 68,
|
| 52 |
+
"fn": 72,
|
| 53 |
+
"p": 0.7291,
|
| 54 |
+
"r": 0.7176,
|
| 55 |
+
"f": 0.7233
|
| 56 |
+
},
|
| 57 |
+
"LOC": {
|
| 58 |
+
"tp": 206,
|
| 59 |
+
"fp": 52,
|
| 60 |
+
"fn": 54,
|
| 61 |
+
"p": 0.7984,
|
| 62 |
+
"r": 0.7923,
|
| 63 |
+
"f": 0.7954
|
| 64 |
+
},
|
| 65 |
+
"ORG": {
|
| 66 |
+
"tp": 101,
|
| 67 |
+
"fp": 34,
|
| 68 |
+
"fn": 50,
|
| 69 |
+
"p": 0.7481,
|
| 70 |
+
"r": 0.6689,
|
| 71 |
+
"f": 0.7063
|
| 72 |
+
},
|
| 73 |
+
"DAT": {
|
| 74 |
+
"tp": 62,
|
| 75 |
+
"fp": 25,
|
| 76 |
+
"fn": 17,
|
| 77 |
+
"p": 0.7126,
|
| 78 |
+
"r": 0.7848,
|
| 79 |
+
"f": 0.747
|
| 80 |
+
},
|
| 81 |
+
"micro": {
|
| 82 |
+
"tp": 552,
|
| 83 |
+
"fp": 179,
|
| 84 |
+
"fn": 193,
|
| 85 |
+
"p": 0.7551,
|
| 86 |
+
"r": 0.7409,
|
| 87 |
+
"f": 0.748
|
| 88 |
+
}
|
| 89 |
+
},
|
| 90 |
+
"test": {
|
| 91 |
+
"PER": {
|
| 92 |
+
"tp": 212,
|
| 93 |
+
"fp": 69,
|
| 94 |
+
"fn": 85,
|
| 95 |
+
"p": 0.7544,
|
| 96 |
+
"r": 0.7138,
|
| 97 |
+
"f": 0.7336
|
| 98 |
+
},
|
| 99 |
+
"LOC": {
|
| 100 |
+
"tp": 225,
|
| 101 |
+
"fp": 46,
|
| 102 |
+
"fn": 48,
|
| 103 |
+
"p": 0.8303,
|
| 104 |
+
"r": 0.8242,
|
| 105 |
+
"f": 0.8272
|
| 106 |
+
},
|
| 107 |
+
"ORG": {
|
| 108 |
+
"tp": 94,
|
| 109 |
+
"fp": 39,
|
| 110 |
+
"fn": 50,
|
| 111 |
+
"p": 0.7068,
|
| 112 |
+
"r": 0.6528,
|
| 113 |
+
"f": 0.6787
|
| 114 |
+
},
|
| 115 |
+
"DAT": {
|
| 116 |
+
"tp": 54,
|
| 117 |
+
"fp": 30,
|
| 118 |
+
"fn": 15,
|
| 119 |
+
"p": 0.6429,
|
| 120 |
+
"r": 0.7826,
|
| 121 |
+
"f": 0.7059
|
| 122 |
+
},
|
| 123 |
+
"micro": {
|
| 124 |
+
"tp": 585,
|
| 125 |
+
"fp": 184,
|
| 126 |
+
"fn": 198,
|
| 127 |
+
"p": 0.7607,
|
| 128 |
+
"r": 0.7471,
|
| 129 |
+
"f": 0.7539
|
| 130 |
+
}
|
| 131 |
+
}
|
| 132 |
+
}
|
| 133 |
+
}
|
llm/dev.iob
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
llm/dev.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
llm/dropped-entities.jsonl
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{"id": "train-s6", "text": "ارسطو", "label": "PER", "reason": "no-align"}
|
| 2 |
+
{"id": "train-s23", "text": "شوروی", "label": "LOC", "reason": "no-align"}
|
| 3 |
+
{"id": "train-s37", "text": "وزارت امور خارجه", "label": "ORG", "reason": "no-align"}
|
| 4 |
+
{"id": "train-s269", "text": "از سالهای 1937 تا 1945", "label": "DAT", "reason": "no-align"}
|
| 5 |
+
{"id": "train-s426", "text": "اسپانیاست", "label": "LOC", "reason": "no-align"}
|
| 6 |
+
{"id": "train-s2984", "text": "حسینی", "label": "PER", "reason": "no-align"}
|
| 7 |
+
{"id": "train-s3018", "text": "رضاخان", "label": "PER", "reason": "no-align"}
|
| 8 |
+
{"id": "train-s3137", "text": "نواب صفوی", "label": "PER", "reason": "no-align"}
|
| 9 |
+
{"id": "train-s3562", "text": "روز پنجشنبه", "label": "DAT", "reason": "no-align"}
|
| 10 |
+
{"id": "train-s4699", "text": "اشکانیان", "label": "O", "reason": "bad-label"}
|
| 11 |
+
{"id": "train-s6682", "text": "فرانتس کافکاست", "label": "PER", "reason": "no-align"}
|
| 12 |
+
{"id": "train-s8679", "text": "طالبان", "label": "ORG", "reason": "no-align"}
|
| 13 |
+
{"id": "train-s9406", "text": "امروز", "label": "DAT", "reason": "no-align"}
|
| 14 |
+
{"id": "train-s11757", "text": "فرانسه", "label": "LOC", "reason": "no-align"}
|
| 15 |
+
{"id": "train-s12087", "text": "ابومازن", "label": "PER", "reason": "no-align"}
|
| 16 |
+
{"id": "train-s12847", "text": "حضرت یوسف", "label": "PER", "reason": "no-align"}
|
| 17 |
+
{"id": "train-s13575", "text": "پژاک", "label": "ORG", "reason": "no-align"}
|
| 18 |
+
{"id": "train-s14461", "text": "منا", "label": "LOC", "reason": "no-align"}
|
| 19 |
+
{"id": "train-s14552", "text": "وزارت امور خارجه آمریکا", "label": "ORG", "reason": "no-align"}
|
| 20 |
+
{"id": "train-s15575", "text": "الکسا", "label": "ORG", "reason": "no-align"}
|
| 21 |
+
{"id": "train-s15892", "text": "محمد", "label": "PER", "reason": "no-align"}
|
| 22 |
+
{"id": "train-s16126", "text": "وزارت امور خارجهٔ ایران", "label": "ORG", "reason": "no-align"}
|
| 23 |
+
{"id": "train-s16391", "text": "مهناز", "label": "PER", "reason": "no-align"}
|
| 24 |
+
{"id": "train-s17795", "text": "ابوسفیان", "label": "PER", "reason": "no-align"}
|
| 25 |
+
{"id": "train-s18483", "text": "اسرائیل", "label": "LOC", "reason": "no-align"}
|
| 26 |
+
{"id": "train-s18911", "text": "شب دهم", "label": "O", "reason": "bad-label"}
|
| 27 |
+
{"id": "train-s18967", "text": "سورهٔ شوری", "label": "O", "reason": "bad-label"}
|
| 28 |
+
{"id": "train-s19256", "text": "وزارت امور خارجهٔ روسیه", "label": "ORG", "reason": "no-align"}
|
| 29 |
+
{"id": "train-s20032", "text": "گوگل", "label": "ORG", "reason": "no-align"}
|
| 30 |
+
{"id": "train-s20150", "text": "از جولای تا دسامبر سال جاری", "label": "DAT", "reason": "no-align"}
|
| 31 |
+
{"id": "train-s20310", "text": "مازندرانی", "label": "O", "reason": "bad-label"}
|
| 32 |
+
{"id": "train-s20989", "text": "مکه", "label": "LOC", "reason": "no-align"}
|
| 33 |
+
{"id": "train-s20994", "text": "ارسطو", "label": "PER", "reason": "no-align"}
|
| 34 |
+
{"id": "train-s21304", "text": "سورهٔ النحل", "label": "O", "reason": "bad-label"}
|
| 35 |
+
{"id": "train-s23704", "text": "کعبه", "label": "LOC", "reason": "no-align"}
|
| 36 |
+
{"id": "train-s25920", "text": "رسول خدا", "label": "PER", "reason": "no-align"}
|
| 37 |
+
{"id": "dev-s48", "text": "سال آینده", "label": "DAT", "reason": "no-align"}
|
| 38 |
+
{"id": "dev-s779", "text": "آفریقاست", "label": "LOC", "reason": "no-align"}
|
| 39 |
+
{"id": "test-s15", "text": "فاطمه", "label": "PER", "reason": "no-align"}
|
| 40 |
+
{"id": "test-s825", "text": "آمریکا", "label": "LOC", "reason": "no-align"}
|
| 41 |
+
{"id": "test-s1071", "text": "زینبم", "label": "PER", "reason": "no-align"}
|
| 42 |
+
{"id": "test-s1107", "text": "ایران", "label": "LOC", "reason": "overlap"}
|
llm/test.iob
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
llm/test.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
llm/train.iob
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
llm/train.jsonl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9e6bce9b0452204fd0c93db453cbc03a6e3717b6fd77e883736ab4a791d401ba
|
| 3 |
+
size 10933626
|
manifest.json
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"dataset": "Phazel/fa-perdt-ner",
|
| 3 |
+
"built_at": "2026-09-22T10:40:29+00:00",
|
| 4 |
+
"build_commit": "eee17c597cdde49e78cddbb28e3e2ef10568b4d7",
|
| 5 |
+
"build_script": "scripts/annotation/build_hub_dataset.py",
|
| 6 |
+
"source_assets": [
|
| 7 |
+
{
|
| 8 |
+
"dest": "assets/ud/fa_perdt-ud-train.conllu",
|
| 9 |
+
"url": "https://raw.githubusercontent.com/UniversalDependencies/UD_Persian-PerDT/master/fa_perdt-ud-train.conllu",
|
| 10 |
+
"md5": "f5a8ba901a776b4fd1941ecadcc6d506"
|
| 11 |
+
},
|
| 12 |
+
{
|
| 13 |
+
"dest": "assets/ud/fa_perdt-ud-dev.conllu",
|
| 14 |
+
"url": "https://raw.githubusercontent.com/UniversalDependencies/UD_Persian-PerDT/master/fa_perdt-ud-dev.conllu",
|
| 15 |
+
"md5": "f103020da7c1e917aafb8a8321f4cb84"
|
| 16 |
+
},
|
| 17 |
+
{
|
| 18 |
+
"dest": "assets/ud/fa_perdt-ud-test.conllu",
|
| 19 |
+
"url": "https://raw.githubusercontent.com/UniversalDependencies/UD_Persian-PerDT/master/fa_perdt-ud-test.conllu",
|
| 20 |
+
"md5": "b62a66994cef2c50f7e524a1471102d8"
|
| 21 |
+
},
|
| 22 |
+
{
|
| 23 |
+
"dest": "assets/ud-ner/train_with_NER_tag.txt",
|
| 24 |
+
"url": "https://raw.githubusercontent.com/UniversalDependencies/UD_Persian-PerDT/master/not-to-release/Dadegan%20with%20NER%20tag/train_with_NER_tag.txt",
|
| 25 |
+
"md5": "ecb96cf99b38bc485cac21d22914e413"
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"dest": "assets/ud-ner/dev_with_NER_tag.txt",
|
| 29 |
+
"url": "https://raw.githubusercontent.com/UniversalDependencies/UD_Persian-PerDT/master/not-to-release/Dadegan%20with%20NER%20tag/dev_with_NER_tag.txt",
|
| 30 |
+
"md5": "2a56ef7eb2e3732e221317af457d1c09"
|
| 31 |
+
},
|
| 32 |
+
{
|
| 33 |
+
"dest": "assets/ud-ner/test_with_NER_tag.txt",
|
| 34 |
+
"url": "https://raw.githubusercontent.com/UniversalDependencies/UD_Persian-PerDT/master/not-to-release/Dadegan%20with%20NER%20tag/test_with_NER_tag.txt",
|
| 35 |
+
"md5": "6d80dd783527562c2ea5189f218a12b5"
|
| 36 |
+
}
|
| 37 |
+
],
|
| 38 |
+
"silver": {
|
| 39 |
+
"labels": [
|
| 40 |
+
"PER",
|
| 41 |
+
"LOC",
|
| 42 |
+
"ORG",
|
| 43 |
+
"DAT",
|
| 44 |
+
"MON",
|
| 45 |
+
"TIM",
|
| 46 |
+
"PCT"
|
| 47 |
+
],
|
| 48 |
+
"transfer_script": "scripts/transfer_perdt_ner.py"
|
| 49 |
+
},
|
| 50 |
+
"llm": {
|
| 51 |
+
"labels": [
|
| 52 |
+
"PER",
|
| 53 |
+
"LOC",
|
| 54 |
+
"ORG",
|
| 55 |
+
"DAT"
|
| 56 |
+
],
|
| 57 |
+
"guideline_version": "2.2",
|
| 58 |
+
"prompt_hash": "3c5f435761a2",
|
| 59 |
+
"model": [
|
| 60 |
+
"default"
|
| 61 |
+
],
|
| 62 |
+
"model_note": "alias as passed to the annotator; the resolved model id was not recorded at run time",
|
| 63 |
+
"unannotated_sentences": [
|
| 64 |
+
"train-s16861"
|
| 65 |
+
],
|
| 66 |
+
"dropped_entities": 42
|
| 67 |
+
},
|
| 68 |
+
"splits": {
|
| 69 |
+
"train": {
|
| 70 |
+
"sentences": 26196,
|
| 71 |
+
"tokens": 445587,
|
| 72 |
+
"silver_entities": {
|
| 73 |
+
"PER": 4847,
|
| 74 |
+
"LOC": 4954,
|
| 75 |
+
"ORG": 2643,
|
| 76 |
+
"DAT": 1323,
|
| 77 |
+
"MON": 205,
|
| 78 |
+
"TIM": 135,
|
| 79 |
+
"PCT": 121
|
| 80 |
+
},
|
| 81 |
+
"llm_entities": {
|
| 82 |
+
"PER": 4771,
|
| 83 |
+
"LOC": 5011,
|
| 84 |
+
"ORG": 2278,
|
| 85 |
+
"DAT": 1584
|
| 86 |
+
}
|
| 87 |
+
},
|
| 88 |
+
"dev": {
|
| 89 |
+
"sentences": 1456,
|
| 90 |
+
"tokens": 24751,
|
| 91 |
+
"silver_entities": {
|
| 92 |
+
"PER": 255,
|
| 93 |
+
"LOC": 260,
|
| 94 |
+
"ORG": 151,
|
| 95 |
+
"DAT": 79,
|
| 96 |
+
"MON": 11,
|
| 97 |
+
"TIM": 8,
|
| 98 |
+
"PCT": 9
|
| 99 |
+
},
|
| 100 |
+
"llm_entities": {
|
| 101 |
+
"PER": 251,
|
| 102 |
+
"LOC": 258,
|
| 103 |
+
"ORG": 135,
|
| 104 |
+
"DAT": 87
|
| 105 |
+
}
|
| 106 |
+
},
|
| 107 |
+
"test": {
|
| 108 |
+
"sentences": 1455,
|
| 109 |
+
"tokens": 23825,
|
| 110 |
+
"silver_entities": {
|
| 111 |
+
"PER": 297,
|
| 112 |
+
"LOC": 273,
|
| 113 |
+
"ORG": 144,
|
| 114 |
+
"DAT": 69,
|
| 115 |
+
"MON": 10,
|
| 116 |
+
"TIM": 9,
|
| 117 |
+
"PCT": 4
|
| 118 |
+
},
|
| 119 |
+
"llm_entities": {
|
| 120 |
+
"PER": 281,
|
| 121 |
+
"LOC": 271,
|
| 122 |
+
"ORG": 133,
|
| 123 |
+
"DAT": 84
|
| 124 |
+
}
|
| 125 |
+
}
|
| 126 |
+
},
|
| 127 |
+
"agreement": {
|
| 128 |
+
"train": {
|
| 129 |
+
"PER": {
|
| 130 |
+
"tp": 3443,
|
| 131 |
+
"fp": 1328,
|
| 132 |
+
"fn": 1404,
|
| 133 |
+
"p": 0.7217,
|
| 134 |
+
"r": 0.7103,
|
| 135 |
+
"f": 0.7159
|
| 136 |
+
},
|
| 137 |
+
"LOC": {
|
| 138 |
+
"tp": 4063,
|
| 139 |
+
"fp": 948,
|
| 140 |
+
"fn": 891,
|
| 141 |
+
"p": 0.8108,
|
| 142 |
+
"r": 0.8201,
|
| 143 |
+
"f": 0.8155
|
| 144 |
+
},
|
| 145 |
+
"ORG": {
|
| 146 |
+
"tp": 1661,
|
| 147 |
+
"fp": 617,
|
| 148 |
+
"fn": 982,
|
| 149 |
+
"p": 0.7291,
|
| 150 |
+
"r": 0.6285,
|
| 151 |
+
"f": 0.6751
|
| 152 |
+
},
|
| 153 |
+
"DAT": {
|
| 154 |
+
"tp": 1006,
|
| 155 |
+
"fp": 578,
|
| 156 |
+
"fn": 317,
|
| 157 |
+
"p": 0.6351,
|
| 158 |
+
"r": 0.7604,
|
| 159 |
+
"f": 0.6921
|
| 160 |
+
},
|
| 161 |
+
"micro": {
|
| 162 |
+
"tp": 10173,
|
| 163 |
+
"fp": 3471,
|
| 164 |
+
"fn": 3594,
|
| 165 |
+
"p": 0.7456,
|
| 166 |
+
"r": 0.7389,
|
| 167 |
+
"f": 0.7423
|
| 168 |
+
}
|
| 169 |
+
},
|
| 170 |
+
"dev": {
|
| 171 |
+
"PER": {
|
| 172 |
+
"tp": 183,
|
| 173 |
+
"fp": 68,
|
| 174 |
+
"fn": 72,
|
| 175 |
+
"p": 0.7291,
|
| 176 |
+
"r": 0.7176,
|
| 177 |
+
"f": 0.7233
|
| 178 |
+
},
|
| 179 |
+
"LOC": {
|
| 180 |
+
"tp": 206,
|
| 181 |
+
"fp": 52,
|
| 182 |
+
"fn": 54,
|
| 183 |
+
"p": 0.7984,
|
| 184 |
+
"r": 0.7923,
|
| 185 |
+
"f": 0.7954
|
| 186 |
+
},
|
| 187 |
+
"ORG": {
|
| 188 |
+
"tp": 101,
|
| 189 |
+
"fp": 34,
|
| 190 |
+
"fn": 50,
|
| 191 |
+
"p": 0.7481,
|
| 192 |
+
"r": 0.6689,
|
| 193 |
+
"f": 0.7063
|
| 194 |
+
},
|
| 195 |
+
"DAT": {
|
| 196 |
+
"tp": 62,
|
| 197 |
+
"fp": 25,
|
| 198 |
+
"fn": 17,
|
| 199 |
+
"p": 0.7126,
|
| 200 |
+
"r": 0.7848,
|
| 201 |
+
"f": 0.747
|
| 202 |
+
},
|
| 203 |
+
"micro": {
|
| 204 |
+
"tp": 552,
|
| 205 |
+
"fp": 179,
|
| 206 |
+
"fn": 193,
|
| 207 |
+
"p": 0.7551,
|
| 208 |
+
"r": 0.7409,
|
| 209 |
+
"f": 0.748
|
| 210 |
+
}
|
| 211 |
+
},
|
| 212 |
+
"test": {
|
| 213 |
+
"PER": {
|
| 214 |
+
"tp": 212,
|
| 215 |
+
"fp": 69,
|
| 216 |
+
"fn": 85,
|
| 217 |
+
"p": 0.7544,
|
| 218 |
+
"r": 0.7138,
|
| 219 |
+
"f": 0.7336
|
| 220 |
+
},
|
| 221 |
+
"LOC": {
|
| 222 |
+
"tp": 225,
|
| 223 |
+
"fp": 46,
|
| 224 |
+
"fn": 48,
|
| 225 |
+
"p": 0.8303,
|
| 226 |
+
"r": 0.8242,
|
| 227 |
+
"f": 0.8272
|
| 228 |
+
},
|
| 229 |
+
"ORG": {
|
| 230 |
+
"tp": 94,
|
| 231 |
+
"fp": 39,
|
| 232 |
+
"fn": 50,
|
| 233 |
+
"p": 0.7068,
|
| 234 |
+
"r": 0.6528,
|
| 235 |
+
"f": 0.6787
|
| 236 |
+
},
|
| 237 |
+
"DAT": {
|
| 238 |
+
"tp": 54,
|
| 239 |
+
"fp": 30,
|
| 240 |
+
"fn": 15,
|
| 241 |
+
"p": 0.6429,
|
| 242 |
+
"r": 0.7826,
|
| 243 |
+
"f": 0.7059
|
| 244 |
+
},
|
| 245 |
+
"micro": {
|
| 246 |
+
"tp": 585,
|
| 247 |
+
"fp": 184,
|
| 248 |
+
"fn": 198,
|
| 249 |
+
"p": 0.7607,
|
| 250 |
+
"r": 0.7471,
|
| 251 |
+
"f": 0.7539
|
| 252 |
+
}
|
| 253 |
+
}
|
| 254 |
+
},
|
| 255 |
+
"files": {
|
| 256 |
+
"LICENSE": {
|
| 257 |
+
"bytes": 22339,
|
| 258 |
+
"sha256": "28ce42d5fc712c6eb4816ccbddfc0d127ccd7cc1e1f1a797219729cdc9ffccf3"
|
| 259 |
+
},
|
| 260 |
+
"README.md": {
|
| 261 |
+
"bytes": 13620,
|
| 262 |
+
"sha256": "ec4a2105af48413555fed4e1707af8877d03f67282e998b1173b0a1ccc22ea29"
|
| 263 |
+
},
|
| 264 |
+
"annotation/GUIDELINES.md": {
|
| 265 |
+
"bytes": 12643,
|
| 266 |
+
"sha256": "7fc460d05a2236df55a60c3c9e061a7a2e65d95aad6711dc868788be95324909"
|
| 267 |
+
},
|
| 268 |
+
"annotation/prompt-v2.2.md": {
|
| 269 |
+
"bytes": 3483,
|
| 270 |
+
"sha256": "7451252f9669b01001e04a69b367c2e835f1043694033dcef792ecda23b4d8bc"
|
| 271 |
+
},
|
| 272 |
+
"annotation/scripts/annotate.js": {
|
| 273 |
+
"bytes": 6673,
|
| 274 |
+
"sha256": "a2da4690b003fa6e77ecfccdf80b1b93b34652bc0c443d1c15bc71b364f1b0ec"
|
| 275 |
+
},
|
| 276 |
+
"annotation/scripts/build_requests.py": {
|
| 277 |
+
"bytes": 4060,
|
| 278 |
+
"sha256": "061a51813863a341ae0e7cdd3af9dc0e275423dd7ff570394ffd30970a9d41aa"
|
| 279 |
+
},
|
| 280 |
+
"annotation/scripts/compare_to_silver.py": {
|
| 281 |
+
"bytes": 5167,
|
| 282 |
+
"sha256": "4c4efe6e432678a312d21df815047f85aac6ce02175d5dcd6806b865de0a6284"
|
| 283 |
+
},
|
| 284 |
+
"annotation/scripts/export_iob.py": {
|
| 285 |
+
"bytes": 3250,
|
| 286 |
+
"sha256": "975f95fb1600c6cf19b958845aee87e794a96f2d2727c858b73a62cdf53cd8cf"
|
| 287 |
+
},
|
| 288 |
+
"annotation/scripts/sample_gold.py": {
|
| 289 |
+
"bytes": 6216,
|
| 290 |
+
"sha256": "05562932b0d4b46c07ace1abf7b1c9a2586489e265cb5420e7619114e913d9db"
|
| 291 |
+
},
|
| 292 |
+
"annotation/scripts/score_gold.py": {
|
| 293 |
+
"bytes": 8972,
|
| 294 |
+
"sha256": "3c29244e9d38570dfabbe5210e91106104357bdedf54e034795d180b8371d316"
|
| 295 |
+
},
|
| 296 |
+
"annotation/scripts/select_sentences.py": {
|
| 297 |
+
"bytes": 6949,
|
| 298 |
+
"sha256": "58b656aff8f079e5d7210d7db008fc1356c43205c182905f448575c8eebf13b7"
|
| 299 |
+
},
|
| 300 |
+
"annotation/scripts/validate_responses.py": {
|
| 301 |
+
"bytes": 5094,
|
| 302 |
+
"sha256": "048e05d030b80946f34bb2de30bebde0a3f3ecaa5158145ce04debe2d378c237"
|
| 303 |
+
},
|
| 304 |
+
"llm/agreement.json": {
|
| 305 |
+
"bytes": 2344,
|
| 306 |
+
"sha256": "3eb62662a7674ee423b1d9f4846ccb5e443cd031d387e46886808daf9dab880f"
|
| 307 |
+
},
|
| 308 |
+
"llm/dev.iob": {
|
| 309 |
+
"bytes": 268875,
|
| 310 |
+
"sha256": "94e0824b3c965dad29b63e8e8f4a54f6d934d165df349eba480624e610ff8a31"
|
| 311 |
+
},
|
| 312 |
+
"llm/dev.jsonl": {
|
| 313 |
+
"bytes": 600958,
|
| 314 |
+
"sha256": "5c2e211c456cb292a1100717624c35cb7a1b7268b58ca2723fdf8df56472b7e6"
|
| 315 |
+
},
|
| 316 |
+
"llm/dropped-entities.jsonl": {
|
| 317 |
+
"bytes": 3733,
|
| 318 |
+
"sha256": "0f023560f2e63bc37293078d4a7825b5ff8b14075fc7bfc38ee2909f2421fa02"
|
| 319 |
+
},
|
| 320 |
+
"llm/test.iob": {
|
| 321 |
+
"bytes": 259224,
|
| 322 |
+
"sha256": "7bf360aca1d5591ab9c9a80447d9f7b85cb5d0bba87def03672fb324ba0b8cd8"
|
| 323 |
+
},
|
| 324 |
+
"llm/test.jsonl": {
|
| 325 |
+
"bytes": 588407,
|
| 326 |
+
"sha256": "8d0df12fae9246cc7e8711d1e8f9cbc6b06157d4c4ff2c97bbba0fe9d33b07cf"
|
| 327 |
+
},
|
| 328 |
+
"llm/train.iob": {
|
| 329 |
+
"bytes": 4850913,
|
| 330 |
+
"sha256": "4548409e42f9d2a1bb1d65b8a619dda1280b36c9d426e98070f1291c755c6a89"
|
| 331 |
+
},
|
| 332 |
+
"llm/train.jsonl": {
|
| 333 |
+
"bytes": 10933626,
|
| 334 |
+
"sha256": "9e6bce9b0452204fd0c93db453cbc03a6e3717b6fd77e883736ab4a791d401ba"
|
| 335 |
+
},
|
| 336 |
+
"silver/dev.iob": {
|
| 337 |
+
"bytes": 269559,
|
| 338 |
+
"sha256": "9d7776fb0ddc0798889535e3e1cb0af500ff48d42da54603182e6e216ee12e66"
|
| 339 |
+
},
|
| 340 |
+
"silver/dev.jsonl": {
|
| 341 |
+
"bytes": 482518,
|
| 342 |
+
"sha256": "603aff36dc54c7386d8d9126812324802a1e689f99281d8a4847d4e7cd6c576c"
|
| 343 |
+
},
|
| 344 |
+
"silver/test.iob": {
|
| 345 |
+
"bytes": 259768,
|
| 346 |
+
"sha256": "731ffe2775c0522e0dfbe3ab987616156111b7d0c740587c356ec1845fbf36e3"
|
| 347 |
+
},
|
| 348 |
+
"silver/test.jsonl": {
|
| 349 |
+
"bytes": 468567,
|
| 350 |
+
"sha256": "23d6df06ca4bdce7baad20de79e8419807fb51bcadcf9dbed0215b6ab5cf2ab3"
|
| 351 |
+
},
|
| 352 |
+
"silver/train.iob": {
|
| 353 |
+
"bytes": 4863985,
|
| 354 |
+
"sha256": "253d6dc85687a3e2aeae6c94adfe233226c3644a0b2bf502a5130a59da6ea450"
|
| 355 |
+
},
|
| 356 |
+
"silver/train.jsonl": {
|
| 357 |
+
"bytes": 8784385,
|
| 358 |
+
"sha256": "8dccbeed73ab583cc25b57406bbaa95ad063848961a311d4aa2a63bf0e62c34d"
|
| 359 |
+
}
|
| 360 |
+
}
|
| 361 |
+
}
|
silver/dev.iob
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
silver/dev.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
silver/test.iob
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
silver/test.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
silver/train.iob
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
silver/train.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|