Megrez v1.1.3 // Nerf the additional weights to the balanced score.
This commit is contained in:
parent
ba595c475e
commit
0bcaa61656
|
@ -193,8 +193,7 @@ extension Megrez {
|
||||||
// 利用幅位長度來決定權重。
|
// 利用幅位長度來決定權重。
|
||||||
// 這樣一來,例:「再見」比「在」與「見」的權重更高。
|
// 這樣一來,例:「再見」比「在」與「見」的權重更高。
|
||||||
if balanced {
|
if balanced {
|
||||||
let weightedScore: Double = (Double(n.spanningLength) - 1) * 2
|
n.accumulatedScore += n.additionalWeights
|
||||||
n.accumulatedScore += weightedScore
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var path: [NodeAnchor] = reverseWalk(
|
var path: [NodeAnchor] = reverseWalk(
|
||||||
|
|
|
@ -204,33 +204,33 @@ extension Megrez {
|
||||||
|
|
||||||
extension Megrez.Grid {
|
extension Megrez.Grid {
|
||||||
public var dumpDOT: String {
|
public var dumpDOT: String {
|
||||||
var sst = "digraph {\ngraph [ rankdir=LR ];\nBOS;\n"
|
var strOutput = "digraph {\ngraph [ rankdir=LR ];\nBOS;\n"
|
||||||
for (p, span) in mutSpans.enumerated() {
|
for (p, span) in mutSpans.enumerated() {
|
||||||
for ni in 0...(span.maximumLength) {
|
for ni in 0...(span.maximumLength) {
|
||||||
guard let np: Megrez.Node = span.node(length: ni) else {
|
guard let np: Megrez.Node = span.node(length: ni) else {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if p == 0 {
|
if p == 0 {
|
||||||
sst += "BOS -> \(np.currentKeyValue.value);\n"
|
strOutput += "BOS -> \(np.currentKeyValue.value);\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
sst += "\(np.currentKeyValue.value);\n"
|
strOutput += "\(np.currentKeyValue.value);\n"
|
||||||
|
|
||||||
if (p + ni) < mutSpans.count {
|
if (p + ni) < mutSpans.count {
|
||||||
let dstSpan = mutSpans[p + ni]
|
let destinatedSpan = mutSpans[p + ni]
|
||||||
for q in 0...(dstSpan.maximumLength) {
|
for q in 0...(destinatedSpan.maximumLength) {
|
||||||
if let dn = dstSpan.node(length: q) {
|
if let dn = destinatedSpan.node(length: q) {
|
||||||
sst += np.currentKeyValue.value + " -> " + dn.currentKeyValue.value + ";\n"
|
strOutput += np.currentKeyValue.value + " -> " + dn.currentKeyValue.value + ";\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p + ni) == mutSpans.count {
|
if (p + ni) == mutSpans.count {
|
||||||
sst += np.currentKeyValue.value + " -> EOS;\n"
|
strOutput += np.currentKeyValue.value + " -> EOS;\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sst += "EOS;\n}\n"
|
strOutput += "EOS;\n}\n"
|
||||||
return sst
|
return strOutput
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,11 +52,19 @@ extension Megrez {
|
||||||
return stream
|
return stream
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 獲取加權量。
|
||||||
|
public var additionalWeights: Double {
|
||||||
|
(Double(spanningLength) - 1) * 0.75
|
||||||
|
}
|
||||||
|
|
||||||
/// 獲取平衡權重。
|
/// 獲取平衡權重。
|
||||||
public var balancedScore: Double {
|
public var balancedScore: Double {
|
||||||
let weightedScore: Double = (Double(spanningLength) - 1) * 2
|
(node?.score ?? 0) + additionalWeights
|
||||||
let nodeScore: Double = node?.score ?? 0
|
}
|
||||||
return weightedScore + nodeScore
|
|
||||||
|
/// 獲取平衡累計權重。
|
||||||
|
public var balancedAccumulatedScore: Double {
|
||||||
|
accumulatedScore + additionalWeights
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue