Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Curio
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
Jim Wallace
Curio
Commits
095f0aa0
Commit
095f0aa0
authored
1 year ago
by
Jim Wallace
Browse files
Options
Downloads
Patches
Plain Diff
Commenting out AnnoyTest code
parent
131b61ec
No related branches found
No related tags found
No related merge requests found
Pipeline
#108402
passed with warnings
1 year ago
Stage: build
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Sources/SwiftNLP/2. Embeddings/KeyedVectorDictionary.swift
+22
-17
22 additions, 17 deletions
Sources/SwiftNLP/2. Embeddings/KeyedVectorDictionary.swift
Tests/SwiftNLPTests/SwiftAnnoyTest.swift
+2
-2
2 additions, 2 deletions
Tests/SwiftNLPTests/SwiftAnnoyTest.swift
with
24 additions
and
19 deletions
Sources/SwiftNLP/2. Embeddings/KeyedVectorDictionary.swift
+
22
−
17
View file @
095f0aa0
...
...
@@ -22,7 +22,12 @@
// OTHER DEALINGS IN THE SOFTWARE.
import
Foundation
#if os(Darwin)
import
SwiftAnnoy
#else
#warning("Need an alternative to SwiftAnnoy for Linux")
#endif
class
KeyedVectorDictionary
:
SNLPDictionary
{
...
...
@@ -192,22 +197,22 @@ class KeyedVectorDictionary: SNLPDictionary {
}
}
func
AnnoyTest
()
->
(
AnnoyIndex
<
Double
>
,
[
Int
:
String
])
{
let
index
=
AnnoyIndex
<
Double
>
(
itemLength
:
width
,
metric
:
.
euclidean
)
var
map
=
[
Int
:
String
]()
var
idx
=
0
;
for
(
key
,
_
)
in
token2id
{
map
[
idx
]
=
key
try!
index
.
addItem
(
index
:
idx
,
vector
:
&
token2id
[
key
]
!
)
idx
+=
1
}
// You can make the number of trees larger number to make the results more accurate
try
?
index
.
build
(
numTrees
:
10
)
return
(
index
,
map
)
}
//
func AnnoyTest() -> (AnnoyIndex<Double>, [Int : String]) {
//
let index = AnnoyIndex<Double>(itemLength: width, metric: .euclidean)
//
//
var map = [Int : String]()
//
var idx = 0;
//
//
for (key, _ ) in token2id {
//
map[idx] = key
//
try! index.addItem(index: idx, vector: &token2id[key]!)
//
idx += 1
//
}
//
//
// You can make the number of trees larger number to make the results more accurate
//
try? index.build(numTrees: 10)
//
//
return (index, map)
//
}
}
This diff is collapsed.
Click to expand it.
Tests/SwiftNLPTests/SwiftAnnoyTest.swift
+
2
−
2
View file @
095f0aa0
...
...
@@ -34,7 +34,7 @@ final class SwiftAnnoyTest: XCTestCase {
let
dictionary
=
corpus
.
dictionary
let
(
myIndex
,
_
)
=
dictionary
.
AnnoyTest
()
//
let (myIndex,_) = dictionary.AnnoyTest()
var
frog
=
dictionary
[
"frog"
]
...
...
@@ -44,7 +44,7 @@ final class SwiftAnnoyTest: XCTestCase {
// Change the number of neighbors below
let
(
_
,
_
)
=
myIndex
.
getNNsForVector
(
vector
:
&
frog
,
neighbors
:
10
)
!
//
let (_, _) = myIndex.getNNsForVector(vector: &frog, neighbors: 10)!
// for (id, distance) in zip(ids, distances) {
// debugPrint("\(myMap[id]!) was \(distance)")
...
...
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