No tokens available.
"
values = list(feature_values) if feature_values else []
if len(values) < len(features):
values.extend([0.0] * (len(features) - len(values)))
layout = (layout or "token").lower()
if layout not in {"token", "sentence"}:
layout = "token"
adjacency: Dict[str, List[Tuple[str, float]]] = defaultdict(list)
for feats, val in pairwise:
if len(feats) != 2:
continue
a, b = feats
adjacency[a].append((b, float(val)))
adjacency[b].append((a, float(val)))
if not adjacency and len(features) > 1:
for idx in range(len(features) - 1):
score = 0.5 * (values[idx] + values[idx + 1])
adjacency[features[idx]].append((features[idx + 1], float(score)))
adjacency[features[idx + 1]].append((features[idx], float(score)))
for key in adjacency:
adjacency[key].sort(key=lambda item: abs(item[1]), reverse=True)
view_id = f"interaction-focus-{uuid.uuid4().hex[:10]}"
none_radio = f"{view_id}-focus-none"
radios = [f'',
"".join(radios),
f'',
f'
点击任意{"句子" if layout == "sentence" else "单词"}即可聚焦并查看其与其它片段的互动。
',
'
',
base_html,
"
",
'
',
f'
',
'
',
"".join(panels),
f'重置 / 返回 ',
"
",
"
",
"
",
]
)
def _render_base_listing(
features: List[str],
values: List[float],
adjacency: Dict[str, List[Tuple[str, float]]],
layout: str,
radio_ids: List[str],
) -> str:
max_abs = max((abs(v) for v in values), default=0.0) or 1.0
chunks: List[str] = []
if layout == "sentence":
for idx, token in enumerate(features):
bg, border = _token_colors(values[idx], max_abs)
badges = []
for partner, score in adjacency.get(token, [])[:2]:
sign = "+" if score >= 0 else ""
badges.append(
f"