Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Toponym Geocoding
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Jacques Fize
Toponym Geocoding
Commits
1f6d2ac8
Commit
1f6d2ac8
authored
4 years ago
by
Fize Jacques
Browse files
Options
Downloads
Patches
Plain Diff
Optimisation on ngram embedding
parent
22d47332
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/ngram_index.py
+14
-0
14 additions, 0 deletions
lib/ngram_index.py
train_geocoder.py
+1
-0
1 addition, 0 deletions
train_geocoder.py
with
15 additions
and
0 deletions
lib/ngram_index.py
+
14
−
0
View file @
1f6d2ac8
import
json
import
json
import
numpy
as
np
import
numpy
as
np
import
pandas
as
pd
from
ngram
import
NGram
from
ngram
import
NGram
from
transformers
import
BertTokenizer
from
transformers
import
BertTokenizer
...
@@ -38,6 +39,8 @@ class NgramIndex():
...
@@ -38,6 +39,8 @@ class NgramIndex():
self
.
size
=
n
self
.
size
=
n
self
.
ngram_index
=
{
""
:
0
}
self
.
ngram_index
=
{
""
:
0
}
self
.
index_ngram
=
{
0
:
""
}
self
.
index_ngram
=
{
0
:
""
}
self
.
freq_ngram
=
{}
self
.
cpt
=
0
self
.
cpt
=
0
self
.
max_len
=
0
self
.
max_len
=
0
...
@@ -71,6 +74,17 @@ class NgramIndex():
...
@@ -71,6 +74,17 @@ class NgramIndex():
self
.
cpt
+=
1
self
.
cpt
+=
1
self
.
ngram_index
[
ngram
]
=
self
.
cpt
self
.
ngram_index
[
ngram
]
=
self
.
cpt
self
.
index_ngram
[
self
.
cpt
]
=
ngram
self
.
index_ngram
[
self
.
cpt
]
=
ngram
self
.
freq_ngram
[
ngram
]
=
1
else
:
self
.
freq_ngram
[
ngram
]
+=
1
def
filter_ngram
(
self
,
threshold
=
20
):
freq_data
=
pd
.
DataFrame
(
self
.
freq_ngram
.
items
(),
columns
=
"
ngram freq
"
.
split
())
selected_ngram
=
freq_data
[
freq_data
.
freq
<
threshold
].
ngram
.
values
for
ng
in
selected_ngram
:
index
=
self
.
ngram_index
[
ng
]
del
self
.
ngram_index
[
ng
]
del
self
.
index_ngram
[
index
]
def
encode
(
self
,
word
,
complete
=
True
):
def
encode
(
self
,
word
,
complete
=
True
):
...
...
This diff is collapsed.
Click to expand it.
train_geocoder.py
+
1
−
0
View file @
1f6d2ac8
...
@@ -112,6 +112,7 @@ if args.tokenization_method == "bert":
...
@@ -112,6 +112,7 @@ if args.tokenization_method == "bert":
# Identify all ngram available
# Identify all ngram available
pairs_of_toponym
.
toponym
.
apply
(
lambda
x
:
index
.
split_and_add
(
x
))
pairs_of_toponym
.
toponym
.
apply
(
lambda
x
:
index
.
split_and_add
(
x
))
pairs_of_toponym
.
toponym_context
.
apply
(
lambda
x
:
index
.
split_and_add
(
x
))
pairs_of_toponym
.
toponym_context
.
apply
(
lambda
x
:
index
.
split_and_add
(
x
))
index
.
filter_ngram
()
num_words
=
len
(
index
.
index_ngram
)
# necessary for the embedding matrix
num_words
=
len
(
index
.
index_ngram
)
# necessary for the embedding matrix
...
...
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