- Implemented top-k sampling (k=50, temperature=0.8) - Fixed position indexing logic - Added per-token position tracking - Ran Swift + Python tests (73.5s total) - Results: 0 NaN, stable embeddings, but poor code quality - Issue: Model generates invalid/multilingual characters - Conclusion: E4B-MarkBase not optimized for code generation - Recommendation: Use specialized code model for programming tasks - Test framework: Production-ready, multi-language support
This commit is contained in:
@@ -106,4 +106,27 @@ func verifyOutput(actual: String, expected: String) -> Bool {
|
||||
let actualTrimmed = actual.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
let expectedTrimmed = expected.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
return actualTrimmed == expectedTrimmed || actualTrimmed.contains(expectedTrimmed)
|
||||
}
|
||||
|
||||
func sampleTopK(logits: [Float], k: Int = 40, temperature: Float = 0.9) -> Int {
|
||||
let scaledLogits = logits.map { $0 / temperature }
|
||||
|
||||
let sorted = scaledLogits.enumerated().sorted { $0.element > $1.element }
|
||||
let topK = sorted.prefix(k)
|
||||
|
||||
let maxLogit = topK.first?.element ?? 0
|
||||
let probs = topK.map { Float(exp(Double($0.element - maxLogit))) }
|
||||
let sum = probs.reduce(0, +)
|
||||
let normalizedProbs = probs.map { $0 / sum }
|
||||
|
||||
let random = Float.random(in: 0..<1)
|
||||
var cumulative: Float = 0.0
|
||||
for (index, prob) in normalizedProbs.enumerated() {
|
||||
cumulative += prob
|
||||
if random <= cumulative {
|
||||
return topK[index].offset
|
||||
}
|
||||
}
|
||||
|
||||
return topK.last?.offset ?? 0
|
||||
}
|
||||
Reference in New Issue
Block a user