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
dc84a3d8
Commit
dc84a3d8
authored
1 year ago
by
Mingchung Xia
Browse files
Options
Downloads
Patches
Plain Diff
Added commented alternatives for hnsw io
parent
f4687556
No related branches found
No related tags found
1 merge request
!13
HNSW Implementation with Testcases
Pipeline
#111300
failed
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. Encoding/ContextFreeEncoder + File IO .swift
+27
-0
27 additions, 0 deletions
.../SwiftNLP/2. Encoding/ContextFreeEncoder + File IO .swift
Tests/SwiftNLPTests/HNSWPipelineTest.swift
+1
-0
1 addition, 0 deletions
Tests/SwiftNLPTests/HNSWPipelineTest.swift
with
28 additions
and
0 deletions
Sources/SwiftNLP/2. Encoding/ContextFreeEncoder + File IO .swift
+
27
−
0
View file @
dc84a3d8
...
...
@@ -168,6 +168,21 @@ extension ContextFreeEncoder {
var
hnsw
=
DeterministicSampleVectorIndex
<
[
Scalar
]
>
()
// while index < data.count {
// if let stringRange = data[index...].range(of: "\0".data(using: .utf8)!) {
// let keyData = data[index..<stringRange.lowerBound]
// if let key = String(data: keyData, encoding: .utf8) {
// index = stringRange.upperBound
//
// let valuesData = data[index..<(index + 50 * MemoryLayout<Scalar>.size)]
// let values = valuesData.withUnsafeBytes { Array($0.bindMemory(to: Scalar.self)) }
// hnsw.insert(values)
// }
// } else {
// break
// }
// }
for
_
in
0
..<
count
{
let
vectorData
=
data
[
index
..<
(
index
+
50
*
MemoryLayout
<
Scalar
>.
size
)]
let
vector
=
vectorData
.
withUnsafeBytes
{
Array
(
$0
.
bindMemory
(
to
:
Scalar
.
self
))
}
...
...
@@ -186,6 +201,18 @@ extension ContextFreeEncoder {
do
{
let
content
=
try
String
(
contentsOf
:
url
,
encoding
:
.
utf8
)
let
lines
=
content
.
split
(
separator
:
"
\n
"
)
// var data = DeterministicSampleVectorIndex<[Scalar]>()
//
// for line in lines.dropFirst() {
// let tokens = line.split(separator: " ")
// let word = String(tokens[0])
// let vector = tokens.dropFirst().compactMap { Scalar(Double($0)!) }
// data.insert(vector)
// }
//
// return data
var
hnsw
=
DeterministicSampleVectorIndex
<
[
Scalar
]
>
()
for
line
in
lines
{
let
vector
=
line
.
split
(
separator
:
" "
)
.
compactMap
{
Scalar
(
Double
(
$0
)
!
)
}
...
...
This diff is collapsed.
Click to expand it.
Tests/SwiftNLPTests/HNSWPipelineTest.swift
+
1
−
0
View file @
dc84a3d8
...
...
@@ -5,6 +5,7 @@
//@testable import SwiftNLP
//
//// MARK: See AllMiniLM_pipelineTest.swift
////TODO: Find where TestUtils comes from to fix
//
//final class HNSWPipelineTest: XCTestCase {
//
...
...
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