Merge pull request #546 from microsoft/copilot/fix-c7041bba-c360-467e-8d43-4a01b9cf0197

Fix AttributeError: 'GloVe' object has no attribute 'get_stoi' in EmbeddingsPyTorch.ipynb
This commit is contained in:
Lee Stott 2025-10-03 15:02:54 +01:00 committed by GitHub
commit 0581b4546e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 20 additions and 4 deletions

View File

@ -30,7 +30,11 @@ def encode(x,voc=None,unk=0,tokenizer=tokenizer):
if v in stoi_hash.keys():
stoi = stoi_hash[v]
else:
stoi = v.get_stoi()
# Handle both vocab.vocab objects (with get_stoi() method) and GloVe objects (with stoi attribute)
if hasattr(v, 'get_stoi'):
stoi = v.get_stoi()
else:
stoi = v.stoi
stoi_hash[v]=stoi
return [stoi.get(s,unk) for s in tokenizer(x)]

View File

@ -30,7 +30,11 @@ def encode(x,voc=None,unk=0,tokenizer=tokenizer):
if v in stoi_hash.keys():
stoi = stoi_hash[v]
else:
stoi = v.get_stoi()
# Handle both vocab.vocab objects (with get_stoi() method) and GloVe objects (with stoi attribute)
if hasattr(v, 'get_stoi'):
stoi = v.get_stoi()
else:
stoi = v.stoi
stoi_hash[v]=stoi
return [stoi.get(s,unk) for s in tokenizer(x)]

View File

@ -30,7 +30,11 @@ def encode(x,voc=None,unk=0,tokenizer=tokenizer):
if v in stoi_hash.keys():
stoi = stoi_hash[v]
else:
stoi = v.get_stoi()
# Handle both vocab.vocab objects (with get_stoi() method) and GloVe objects (with stoi attribute)
if hasattr(v, 'get_stoi'):
stoi = v.get_stoi()
else:
stoi = v.stoi
stoi_hash[v]=stoi
return [stoi.get(s,unk) for s in tokenizer(x)]

View File

@ -30,7 +30,11 @@ def encode(x,voc=None,unk=0,tokenizer=tokenizer):
if v in stoi_hash.keys():
stoi = stoi_hash[v]
else:
stoi = v.get_stoi()
# Handle both vocab.vocab objects (with get_stoi() method) and GloVe objects (with stoi attribute)
if hasattr(v, 'get_stoi'):
stoi = v.get_stoi()
else:
stoi = v.stoi
stoi_hash[v]=stoi
return [stoi.get(s,unk) for s in tokenizer(x)]