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
57a7bee4
Commit
57a7bee4
authored
4 years ago
by
Fize Jacques
Browse files
Options
Downloads
Patches
Plain Diff
little UPD
parent
00420f29
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/word_index.py
+11
-11
11 additions, 11 deletions
lib/word_index.py
parser_config/toponym_combination_embedding_v3.json
+3
-2
3 additions, 2 deletions
parser_config/toponym_combination_embedding_v3.json
train_geocoder_v2.py
+8
-2
8 additions, 2 deletions
train_geocoder_v2.py
with
22 additions
and
15 deletions
lib/word_index.py
+
11
−
11
View file @
57a7bee4
...
@@ -20,8 +20,8 @@ class WordIndex():
...
@@ -20,8 +20,8 @@ class WordIndex():
loaded : bool
loaded : bool
if loaded from external file
if loaded from external file
"""
"""
self
.
word
_index
=
{
""
:
0
}
self
.
ngram
_index
=
{
""
:
0
}
self
.
index_
word
=
{
0
:
""
}
self
.
index_
ngram
=
{
0
:
""
}
self
.
cpt
=
0
self
.
cpt
=
0
self
.
max_len
=
0
self
.
max_len
=
0
...
@@ -49,10 +49,10 @@ class WordIndex():
...
@@ -49,10 +49,10 @@ class WordIndex():
ngram : str
ngram : str
ngram
ngram
"""
"""
if
not
subword
in
self
.
word
_index
:
if
not
subword
in
self
.
ngram
_index
:
self
.
cpt
+=
1
self
.
cpt
+=
1
self
.
word
_index
[
subword
]
=
self
.
cpt
self
.
ngram
_index
[
subword
]
=
self
.
cpt
self
.
index_
word
[
self
.
cpt
]
=
subword
self
.
index_
ngram
[
self
.
cpt
]
=
subword
def
encode
(
self
,
word
):
def
encode
(
self
,
word
):
...
@@ -72,10 +72,10 @@ class WordIndex():
...
@@ -72,10 +72,10 @@ class WordIndex():
"""
"""
subwords
=
[
w
.
lower
()
for
w
in
word
.
split
(
"
"
)]
subwords
=
[
w
.
lower
()
for
w
in
word
.
split
(
"
"
)]
if
not
self
.
loaded
:
if
not
self
.
loaded
:
[
self
.
add
(
ng
)
for
ng
in
subwords
if
not
ng
in
self
.
word
_index
]
[
self
.
add
(
ng
)
for
ng
in
subwords
if
not
ng
in
self
.
ngram
_index
]
if
self
.
max_len
<
len
(
subwords
):
if
self
.
max_len
<
len
(
subwords
):
self
.
max_len
=
max
(
self
.
max_len
,
len
(
subwords
))
self
.
max_len
=
max
(
self
.
max_len
,
len
(
subwords
))
return
self
.
complete
([
self
.
word
_index
[
ng
]
for
ng
in
subwords
if
ng
in
self
.
word
_index
],
self
.
max_len
)
return
self
.
complete
([
self
.
ngram
_index
[
ng
]
for
ng
in
subwords
if
ng
in
self
.
ngram
_index
],
self
.
max_len
)
def
complete
(
self
,
ngram_encoding
,
MAX_LEN
,
filling_item
=
0
):
def
complete
(
self
,
ngram_encoding
,
MAX_LEN
,
filling_item
=
0
):
"""
"""
...
@@ -119,7 +119,7 @@ class WordIndex():
...
@@ -119,7 +119,7 @@ class WordIndex():
embedding matrix
embedding matrix
"""
"""
model
=
Word2Vec
([[
str
(
w
)
for
w
in
t
]
for
t
in
texts
],
size
=
dim
,
window
=
5
,
min_count
=
1
,
workers
=
4
,
**
kwargs
)
model
=
Word2Vec
([[
str
(
w
)
for
w
in
t
]
for
t
in
texts
],
size
=
dim
,
window
=
5
,
min_count
=
1
,
workers
=
4
,
**
kwargs
)
N
=
len
(
self
.
word
_index
)
N
=
len
(
self
.
ngram
_index
)
embedding_matrix
=
np
.
zeros
((
N
,
dim
))
embedding_matrix
=
np
.
zeros
((
N
,
dim
))
for
i
in
range
(
N
):
for
i
in
range
(
N
):
if
str
(
i
)
in
model
.
wv
:
if
str
(
i
)
in
model
.
wv
:
...
@@ -137,7 +137,7 @@ class WordIndex():
...
@@ -137,7 +137,7 @@ class WordIndex():
output filename
output filename
"""
"""
data
=
{
data
=
{
"
word_index
"
:
self
.
word
_index
,
"
word_index
"
:
self
.
ngram
_index
,
"
cpt_state
"
:
self
.
cpt
,
"
cpt_state
"
:
self
.
cpt
,
"
max_len_state
"
:
self
.
max_len
"
max_len_state
"
:
self
.
max_len
}
}
...
@@ -172,8 +172,8 @@ class WordIndex():
...
@@ -172,8 +172,8 @@ class WordIndex():
if
not
key
in
data
:
if
not
key
in
data
:
raise
KeyError
(
"
{0} field cannot be found in given file
"
.
format
(
key
))
raise
KeyError
(
"
{0} field cannot be found in given file
"
.
format
(
key
))
new_obj
=
WordIndex
(
loaded
=
True
)
new_obj
=
WordIndex
(
loaded
=
True
)
new_obj
.
word
_index
=
data
[
"
word
_index
"
]
new_obj
.
ngram
_index
=
data
[
"
ngram
_index
"
]
new_obj
.
index_
word
=
{
v
:
k
for
k
,
v
in
new_obj
.
word
_index
.
items
()}
new_obj
.
index_
ngram
=
{
v
:
k
for
k
,
v
in
new_obj
.
ngram
_index
.
items
()}
new_obj
.
cpt
=
data
[
"
cpt_state
"
]
new_obj
.
cpt
=
data
[
"
cpt_state
"
]
new_obj
.
max_len
=
data
[
"
max_len_state
"
]
new_obj
.
max_len
=
data
[
"
max_len_state
"
]
return
new_obj
return
new_obj
...
...
This diff is collapsed.
Click to expand it.
parser_config/toponym_combination_embedding_v3.json
+
3
−
2
View file @
57a7bee4
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
{
"short"
:
"dataset_name"
,
"help"
:
"Filepath of the Geonames file you want to use."
},
{
"short"
:
"dataset_name"
,
"help"
:
"Filepath of the Geonames file you want to use."
},
{
"short"
:
"geoname_inclusion"
,
"help"
:
"Filepath of the Geonames file you want to use."
},
{
"short"
:
"geoname_inclusion"
,
"help"
:
"Filepath of the Geonames file you want to use."
},
{
"short"
:
"geonames_adjacent"
,
"help"
:
"Filepath of the Geonames file you want to use."
},
{
"short"
:
"geonames_adjacent"
,
"help"
:
"Filepath of the Geonames file you want to use."
},
{
"long"
:
"wikipedia_cooc"
,
"help"
:
"Cooccurrence data filename"
},
{
"long"
:
"wikipedia_cooc"
,
"help"
:
"Cooccurrence data filename"
},
{
"short"
:
"-v"
,
"long"
:
"--verbose"
,
"action"
:
"store_true"
},
{
"short"
:
"-v"
,
"long"
:
"--verbose"
,
"action"
:
"store_true"
},
{
"short"
:
"-i"
,
"long"
:
"--inclusion"
,
"action"
:
"store_true"
},
{
"short"
:
"-i"
,
"long"
:
"--inclusion"
,
"action"
:
"store_true"
},
{
"short"
:
"-a"
,
"long"
:
"--adjacency"
,
"action"
:
"store_true"
},
{
"short"
:
"-a"
,
"long"
:
"--adjacency"
,
"action"
:
"store_true"
},
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
{
"short"
:
"-t"
,
"long"
:
"--tolerance-value"
,
"type"
:
"float"
,
"default"
:
100
},
{
"short"
:
"-t"
,
"long"
:
"--tolerance-value"
,
"type"
:
"float"
,
"default"
:
100
},
{
"short"
:
"-e"
,
"long"
:
"--epochs"
,
"type"
:
"int"
,
"default"
:
100
},
{
"short"
:
"-e"
,
"long"
:
"--epochs"
,
"type"
:
"int"
,
"default"
:
100
},
{
"short"
:
"-d"
,
"long"
:
"--dimension"
,
"type"
:
"int"
,
"default"
:
256
},
{
"short"
:
"-d"
,
"long"
:
"--dimension"
,
"type"
:
"int"
,
"default"
:
256
},
{
"short"
:
"-l"
,
"long"
:
"--lstm-layer"
,
"type"
:
"int"
,
"default"
:
2
,
"choices"
:[
1
,
2
]
}
{
"short"
:
"-l"
,
"long"
:
"--lstm-layer"
,
"type"
:
"int"
,
"default"
:
2
,
"choices"
:
[
1
,
2
]
},
{
"long"
:
"--tokenization-method"
,
"type"
:
"str"
,
"default"
:
"char-level"
,
"choices"
:
[
"char-level"
,
"word-level"
]
}
]
]
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
train_geocoder_v2.py
+
8
−
2
View file @
57a7bee4
...
@@ -14,6 +14,7 @@ from keras.callbacks import ModelCheckpoint
...
@@ -14,6 +14,7 @@ from keras.callbacks import ModelCheckpoint
# Custom module
# Custom module
from
lib.utils_geo
import
zero_one_encoding
from
lib.utils_geo
import
zero_one_encoding
from
lib.ngram_index
import
NgramIndex
from
lib.ngram_index
import
NgramIndex
from
lib.word_index
import
WordIndex
from
lib.utils
import
ConfigurationReader
from
lib.utils
import
ConfigurationReader
from
lib.utils_geo
import
accuracy_k
,
haversine_tf_1circle
from
lib.utils_geo
import
accuracy_k
,
haversine_tf_1circle
from
helpers
import
EpochTimer
from
helpers
import
EpochTimer
...
@@ -29,8 +30,11 @@ logging.basicConfig( # LOGGING CONF
...
@@ -29,8 +30,11 @@ logging.basicConfig( # LOGGING CONF
)
)
import
tensorflow
as
tf
import
tensorflow
as
tf
physical_devices
=
tf
.
config
.
list_physical_devices
(
'
GPU
'
)
try
:
tf
.
config
.
experimental
.
set_memory_growth
(
physical_devices
[
0
],
enable
=
True
)
physical_devices
=
tf
.
config
.
list_physical_devices
(
'
GPU
'
)
tf
.
config
.
experimental
.
set_memory_growth
(
physical_devices
[
0
],
enable
=
True
)
except
:
print
(
"
NO GPU FOUND
"
)
# COMMAND ARGS
# COMMAND ARGS
args
=
ConfigurationReader
(
"
./parser_config/toponym_combination_embedding_v3.json
"
)
\
args
=
ConfigurationReader
(
"
./parser_config/toponym_combination_embedding_v3.json
"
)
\
.
parse_args
()
#("IGN ../data/IGN/IGN_inclusion.csv ../data/IGN/IGN_adjacent_corrected.csv ../data/IGN/IGN_cooc.csv -i -w -a -n 4 --ngram-word2vec-iter 1".split())
.
parse_args
()
#("IGN ../data/IGN/IGN_inclusion.csv ../data/IGN/IGN_adjacent_corrected.csv ../data/IGN/IGN_cooc.csv -i -w -a -n 4 --ngram-word2vec-iter 1".split())
...
@@ -97,6 +101,8 @@ pairs_of_toponym = pd.concat(data_used)
...
@@ -97,6 +101,8 @@ pairs_of_toponym = pd.concat(data_used)
# ENCODING NAME USING N-GRAM SPLITTING
# ENCODING NAME USING N-GRAM SPLITTING
logging
.
info
(
"
Encoding toponyms to ngram...
"
)
logging
.
info
(
"
Encoding toponyms to ngram...
"
)
index
=
NgramIndex
(
NGRAM_SIZE
)
index
=
NgramIndex
(
NGRAM_SIZE
)
if
args
.
tokenization_method
==
"
word-level
"
:
index
=
WordIndex
()
# 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
))
...
...
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