Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Analysing and Mitigating Origin Bias in German Word Embeddings
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Aileen Reichelt
Analysing and Mitigating Origin Bias in German Word Embeddings
Commits
0b84d2a3
Commit
0b84d2a3
authored
1 year ago
by
Aileen Reichelt
Browse files
Options
Downloads
Patches
Plain Diff
Add preprocessing and counting scripts
parent
1b1f61c1
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
count_name_occurrences_wikipedia.py
+2
-1
2 additions, 1 deletion
count_name_occurrences_wikipedia.py
count_names_glove_vocab.py
+29
-0
29 additions, 0 deletions
count_names_glove_vocab.py
preprocess_wikipedia.py
+19
-0
19 additions, 0 deletions
preprocess_wikipedia.py
with
50 additions
and
1 deletion
count_name_occurrences_wikipedia.py
+
2
−
1
View file @
0b84d2a3
"""
Check how often the most common names of each nationality
occurr in the Wikipedia snapshot used for GloVe training.
"""
occur in the Wikipedia snapshot used for GloVe training.
To be used when there is no vocab count file yet.
"""
import
pandas
as
pd
...
...
This diff is collapsed.
Click to expand it.
count_names_glove_vocab.py
0 → 100644
+
29
−
0
View file @
0b84d2a3
"""
Short helper script to look up vocab counts of ~400 names in GloVe vocabulary
"""
from
tqdm
import
tqdm
with
open
(
"
names.txt
"
,
"
r
"
,
encoding
=
"
utf-8
"
)
as
names_file
:
names
=
names_file
.
readlines
()
names
=
[
name
.
strip
().
lower
()
for
name
in
names
]
counts
=
[]
with
open
(
"
data/embeddings/glove/dd-glove/vocab.txt
"
,
"
r
"
,
encoding
=
"
utf-8
"
)
as
vocab_file
:
vocab
=
vocab_file
.
readlines
()
for
name
in
tqdm
(
names
):
# this is inefficient but using dictionaries doesn't work
for
line
in
vocab
:
token
,
count
=
line
.
strip
().
split
()
if
token
==
name
:
counts
.
append
(
count
)
found
=
True
break
if
found
==
False
:
counts
.
append
(
0
)
found
=
False
print
(
len
(
names
))
print
(
len
(
counts
))
with
open
(
"
name_counts.csv
"
,
"
w+
"
,
encoding
=
"
utf-8
"
)
as
output
:
for
i
,
name
in
enumerate
(
names
):
output
.
write
(
f
"
{
name
}
,
{
counts
[
i
]
}
\n
"
)
This diff is collapsed.
Click to expand it.
preprocess_wikipedia.py
0 → 100644
+
19
−
0
View file @
0b84d2a3
"""
Download Wikipedia dump using huggingface and preprocess it
using nltk tokenizer, lowercasing, punctuation removal
"""
from
tqdm
import
tqdm
from
nltk.tokenize
import
word_tokenize
from
datasets
import
load_dataset
wikipedia
=
load_dataset
(
"
wikipedia
"
,
"
20220301.en
"
)
wikipedia
=
wikipedia
[
"
train
"
]
with
open
(
"
/workspace/students/reichelt/BA/data/wikipedia/english_wikipedia_preprocessed.txt
"
,
"
w+
"
,
encoding
=
"
utf-8
"
)
as
f
:
for
article
in
tqdm
(
wikipedia
):
tokenized
=
word_tokenize
(
article
[
"
text
"
],
language
=
'
english
'
)
tokenized
=
[
token
.
lower
()
for
token
in
tokenized
]
JOINED
=
"
"
.
join
(
tokenized
)
f
.
write
(
JOINED
+
"
\n
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment