Updated documentation of iOS text embedder tests
This commit is contained in:
parent
e290f9cf30
commit
eeaa011998
|
@ -42,8 +42,7 @@ static const float kSimilarityDiffTolerance = 1e-4;
|
||||||
if (quantized) { \
|
if (quantized) { \
|
||||||
XCTAssertNil(embedding.floatEmbedding); \
|
XCTAssertNil(embedding.floatEmbedding); \
|
||||||
XCTAssertNotNil(embedding.quantizedEmbedding); \
|
XCTAssertNotNil(embedding.quantizedEmbedding); \
|
||||||
} \
|
} else { \
|
||||||
else { \
|
|
||||||
XCTAssertNotNil(embedding.floatEmbedding); \
|
XCTAssertNotNil(embedding.floatEmbedding); \
|
||||||
XCTAssertNil(embedding.quantizedEmbedding); \
|
XCTAssertNil(embedding.quantizedEmbedding); \
|
||||||
}
|
}
|
||||||
|
@ -52,10 +51,9 @@ static const float kSimilarityDiffTolerance = 1e-4;
|
||||||
XCTAssertEqual(embedding.count, expectedLength); \
|
XCTAssertEqual(embedding.count, expectedLength); \
|
||||||
if (quantize) { \
|
if (quantize) { \
|
||||||
XCTAssertEqual(embedding[0].charValue, expectedFirstValue); \
|
XCTAssertEqual(embedding[0].charValue, expectedFirstValue); \
|
||||||
} \
|
} else { \
|
||||||
else { \
|
|
||||||
XCTAssertEqualWithAccuracy(embedding[0].floatValue, expectedFirstValue, kFloatDiffTolerance); \
|
XCTAssertEqualWithAccuracy(embedding[0].floatValue, expectedFirstValue, kFloatDiffTolerance); \
|
||||||
} \
|
}
|
||||||
|
|
||||||
@interface MPPTextEmbedderTests : XCTestCase
|
@interface MPPTextEmbedderTests : XCTestCase
|
||||||
@end
|
@end
|
||||||
|
@ -95,8 +93,7 @@ static const float kSimilarityDiffTolerance = 1e-4;
|
||||||
MPPTextEmbedderResult *embedderResult = [textEmbedder embedText:text error:nil];
|
MPPTextEmbedderResult *embedderResult = [textEmbedder embedText:text error:nil];
|
||||||
AssertTextEmbedderResultHasOneEmbedding(embedderResult);
|
AssertTextEmbedderResultHasOneEmbedding(embedderResult);
|
||||||
|
|
||||||
AssertEmbeddingType(
|
AssertEmbeddingType(embedderResult.embeddingResult.embeddings[0], // embedding
|
||||||
embedderResult.embeddingResult.embeddings[0], // embedding
|
|
||||||
NO // quantized
|
NO // quantized
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -117,8 +114,7 @@ static const float kSimilarityDiffTolerance = 1e-4;
|
||||||
MPPTextEmbedderResult *embedderResult = [textEmbedder embedText:text error:nil];
|
MPPTextEmbedderResult *embedderResult = [textEmbedder embedText:text error:nil];
|
||||||
AssertTextEmbedderResultHasOneEmbedding(embedderResult);
|
AssertTextEmbedderResultHasOneEmbedding(embedderResult);
|
||||||
|
|
||||||
AssertEmbeddingType(
|
AssertEmbeddingType(embedderResult.embeddingResult.embeddings[0], // embedding
|
||||||
embedderResult.embeddingResult.embeddings[0], // embedding
|
|
||||||
YES // quantized
|
YES // quantized
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -148,8 +144,7 @@ static const float kSimilarityDiffTolerance = 1e-4;
|
||||||
@"INVALID_ARGUMENT: ExternalFile must specify at least one of 'file_content', "
|
@"INVALID_ARGUMENT: ExternalFile must specify at least one of 'file_content', "
|
||||||
@"'file_name', 'file_pointer_meta' or 'file_descriptor_meta'."
|
@"'file_name', 'file_pointer_meta' or 'file_descriptor_meta'."
|
||||||
}];
|
}];
|
||||||
AssertEqualErrors(
|
AssertEqualErrors(error, // error
|
||||||
error, // error
|
|
||||||
expectedError // expectedError
|
expectedError // expectedError
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -228,16 +223,20 @@ static const float kSimilarityDiffTolerance = 1e-4;
|
||||||
MPPTextEmbedder *textEmbedder = [[MPPTextEmbedder alloc] initWithOptions:options error:nil];
|
MPPTextEmbedder *textEmbedder = [[MPPTextEmbedder alloc] initWithOptions:options error:nil];
|
||||||
XCTAssertNotNil(textEmbedder);
|
XCTAssertNotNil(textEmbedder);
|
||||||
|
|
||||||
MPPEmbedding *embedding1 = [self assertQuantizedEmbeddingResultsOfEmbedText:@"it's a charming and often affecting journey"
|
MPPEmbedding *embedding1 = [self
|
||||||
|
assertQuantizedEmbeddingResultsOfEmbedText:@"it's a charming and often affecting journey"
|
||||||
usingTextEmbedder:textEmbedder
|
usingTextEmbedder:textEmbedder
|
||||||
hasCount:512
|
hasCount:512
|
||||||
firstValue:127];
|
firstValue:127];
|
||||||
|
|
||||||
MPPEmbedding *embedding2 = [self assertQuantizedEmbeddingResultsOfEmbedText:@"what a great and fantastic trip"
|
MPPEmbedding *embedding2 =
|
||||||
|
[self assertQuantizedEmbeddingResultsOfEmbedText:@"what a great and fantastic trip"
|
||||||
usingTextEmbedder:textEmbedder
|
usingTextEmbedder:textEmbedder
|
||||||
hasCount:512
|
hasCount:512
|
||||||
firstValue:127];
|
firstValue:127];
|
||||||
NSNumber *cosineSimilarity = [MPPTextEmbedder cosineSimilarityBetweenEmbedding1:embedding1 andEmbedding2:embedding2 error:nil];
|
NSNumber *cosineSimilarity = [MPPTextEmbedder cosineSimilarityBetweenEmbedding1:embedding1
|
||||||
|
andEmbedding2:embedding2
|
||||||
|
error:nil];
|
||||||
XCTAssertEqualWithAccuracy(cosineSimilarity.doubleValue, 0.864113, kSimilarityDiffTolerance);
|
XCTAssertEqualWithAccuracy(cosineSimilarity.doubleValue, 0.864113, kSimilarityDiffTolerance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user