Max Activation: {Math.max(...sampleGroup.samples[0].featureActs).toFixed(3)}
- {sampleGroup.samples.slice((page - 1) * 5, page * 5).map((sample, i) => (
+ {sampleGroup.samples.slice((page - 1) * 10, page * 10).map((sample, i) => (
))}
@@ -72,7 +72,7 @@ export const FeatureActivationSample = ({ sample, sampleName, maxFeatureAct }: F
const tokensList = tokens.map((t) => t.featureAct);
const startTrigger = Math.max(tokensList.indexOf(Math.max(...tokensList)) - 100, 0);
- const endTrigger = Math.min(tokensList.indexOf(Math.max(...tokensList)) + 100, sample.context.length);
+ const endTrigger = Math.min(tokensList.indexOf(Math.max(...tokensList)) + 10, sample.context.length);
const tokensTrigger = sample.context.slice(startTrigger, endTrigger).map((token, i) => ({
token,
featureAct: sample.featureActs[startTrigger + i],
@@ -102,7 +102,7 @@ export const FeatureActivationSample = ({ sample, sampleName, maxFeatureAct }: F
return (
-
+
{sampleName &&
{sampleName}: }
From f41fce3e55f37afcc6ac5e35223208a0653526d4 Mon Sep 17 00:00:00 2001
From: Zhu Fukang <105139493+StarConnor@users.noreply.github.com>
Date: Sun, 28 Jul 2024 21:43:43 +0800
Subject: [PATCH 08/11] fix(ui/preview): disable flex to avoid showing long
token
---
ui/src/components/feature/sample.tsx | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/ui/src/components/feature/sample.tsx b/ui/src/components/feature/sample.tsx
index 7157c0b..9fb9a13 100644
--- a/ui/src/components/feature/sample.tsx
+++ b/ui/src/components/feature/sample.tsx
@@ -104,19 +104,17 @@ export const FeatureActivationSample = ({ sample, sampleName, maxFeatureAct }: F
-
+
{sampleName &&
{sampleName}: }
{startTrigger != 0 &&
...}
{tokenGroupsTrigger.map((tokens, i) => (
-
-
-
+
))}
{endTrigger != 0 &&
...}
From 6feab1c9b155c16aad36a67bc9b954d79a651624 Mon Sep 17 00:00:00 2001
From: Zhu Fukang <105139493+StarConnor@users.noreply.github.com>
Date: Sun, 28 Jul 2024 21:47:15 +0800
Subject: [PATCH 09/11] fix(ui/preview): add color to "..." to avoid confuse
---
ui/src/components/feature/sample.tsx | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/ui/src/components/feature/sample.tsx b/ui/src/components/feature/sample.tsx
index 9fb9a13..1b03555 100644
--- a/ui/src/components/feature/sample.tsx
+++ b/ui/src/components/feature/sample.tsx
@@ -106,7 +106,7 @@ export const FeatureActivationSample = ({ sample, sampleName, maxFeatureAct }: F
{sampleName && {sampleName}: }
- {startTrigger != 0 && ...}
+ {startTrigger != 0 && ...}
{tokenGroupsTrigger.map((tokens, i) => (
))}
- {endTrigger != 0 && ...}
+ {endTrigger != 0 && ...}
From 94c8be4837386277cf010747ab79ef334e8446fd Mon Sep 17 00:00:00 2001
From: Dest1n1
Date: Mon, 29 Jul 2024 02:04:59 +0800
Subject: [PATCH 10/11] feat(ui): update style of section navigator
---
ui/src/components/app/section-navigator.tsx | 60 +++++++++++++++
ui/src/components/app/sidenav.tsx | 82 ---------------------
ui/src/components/feature/feature-card.tsx | 4 +-
ui/src/globals.css | 10 ---
ui/src/routes/features/page.tsx | 26 ++++++-
5 files changed, 85 insertions(+), 97 deletions(-)
create mode 100644 ui/src/components/app/section-navigator.tsx
delete mode 100644 ui/src/components/app/sidenav.tsx
diff --git a/ui/src/components/app/section-navigator.tsx b/ui/src/components/app/section-navigator.tsx
new file mode 100644
index 0000000..aaa4637
--- /dev/null
+++ b/ui/src/components/app/section-navigator.tsx
@@ -0,0 +1,60 @@
+import { cn } from "@/lib/utils";
+import { Card, CardContent, CardHeader, CardTitle } from "../ui/card";
+import { useEffect, useState } from "react";
+
+export const SectionNavigator = ({ sections }: { sections: { title: string; id: string }[] }) => {
+ const [activeSection, setActiveSection] = useState<{ title: string; id: string } | null>(null);
+
+ const handleScroll = () => {
+ // Use reduce instead of find for obtaining the last section that is in view
+ const currentSection = sections.reduce((result: { title: string; id: string } | null, section) => {
+ const secElement = document.getElementById(section.id);
+ if (!secElement) return result;
+ const rect = secElement.getBoundingClientRect();
+ if (rect.top <= window.innerHeight / 2) {
+ return section;
+ }
+ return result;
+ }, null);
+
+ setActiveSection(currentSection);
+ };
+
+ useEffect(() => {
+ window.addEventListener("scroll", handleScroll);
+
+ // Run the handler to set the initial active section
+ handleScroll();
+
+ return () => {
+ window.removeEventListener("scroll", handleScroll);
+ };
+ });
+
+ return (
+
+
+
+ CONTENTS
+
+
+
+
+
+ {sections.map((section) => (
+ -
+
+ {section.title}
+
+ {activeSection === section && }
+
+ ))}
+
+
+
+
+ );
+};
diff --git a/ui/src/components/app/sidenav.tsx b/ui/src/components/app/sidenav.tsx
deleted file mode 100644
index 7acf5e0..0000000
--- a/ui/src/components/app/sidenav.tsx
+++ /dev/null
@@ -1,82 +0,0 @@
-import { Card, CardContent, CardHeader, CardTitle } from "../ui/card";
-import { useEffect, useState } from "react";
-
-export const SideNav = ({ logitsExist }: { logitsExist: boolean }) => {
- const [activeId, setActiveId] = useState("");
- let idList;
- if (logitsExist) {
- idList = ["Top", "Hist.", "Logits", "Act."];
- } else {
- idList = ["Top", "Hist.", "Act."];
- }
-
- const handleScroll = () => {
- const sections = document.querySelectorAll("div[id]");
- let currentSectionId = "";
-
- sections.forEach((section) => {
- if (idList.indexOf(section.id) != -1) {
- const rect = section.getBoundingClientRect();
- if (rect.top <= window.innerHeight / 2) {
- currentSectionId = section.id;
- }
- }
- });
-
- setActiveId(currentSectionId);
- };
-
- useEffect(() => {
- window.addEventListener("scroll", handleScroll);
-
- // Run the handler to set the initial active section
- handleScroll();
-
- return () => {
- window.removeEventListener("scroll", handleScroll);
- };
- });
-
- return (
-
-
-
- CONTENTS
-
-
-
-
-
- {idList.map((item) => (
- -
-
- {item}
-
- {activeId === item && (
-
- )}
-
- ))}
-
-
-
-
- );
-};
diff --git a/ui/src/components/feature/feature-card.tsx b/ui/src/components/feature/feature-card.tsx
index 726b3f3..fa41369 100644
--- a/ui/src/components/feature/feature-card.tsx
+++ b/ui/src/components/feature/feature-card.tsx
@@ -108,7 +108,7 @@ export const FeatureCard = ({ feature }: { feature: Feature }) => {
-
+
)}
-
+
{feature.sampleGroups.slice(0, feature.sampleGroups.length / 2).map((sampleGroup) => (
diff --git a/ui/src/globals.css b/ui/src/globals.css
index 99c0901..55ba9eb 100644
--- a/ui/src/globals.css
+++ b/ui/src/globals.css
@@ -78,13 +78,3 @@
html {
scroll-behavior: smooth;
}
-/* Side navigation styles */
-.side-nav {
- position: fixed;
- right: 0;
- top: 0;
- width: 80px;
- height: 100%;
- background-color: #f4f4f4;
- box-shadow: -2px 0 5px rgba(0, 0, 0, 0.1);
-}
diff --git a/ui/src/routes/features/page.tsx b/ui/src/routes/features/page.tsx
index 0734060..58102b8 100644
--- a/ui/src/routes/features/page.tsx
+++ b/ui/src/routes/features/page.tsx
@@ -1,6 +1,6 @@
import { AppNavbar } from "@/components/app/navbar";
import { FeatureCard } from "@/components/feature/feature-card";
-import { SideNav } from "@/components/app/sidenav";
+import { SectionNavigator } from "@/components/app/sidenav";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
@@ -88,10 +88,24 @@ export const FeaturesPage = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [dictionariesState.value]);
+ const sections = [
+ {
+ title: "Histogram",
+ id: "Histogram",
+ },
+ {
+ title: "Logits",
+ id: "Logits",
+ },
+ {
+ title: "Top Activation",
+ id: "Activation",
+ },
+ ].filter((section) => (featureState.value && featureState.value.logits != null) || section.id !== "Logits");
+
return (
-
Select dictionary:
@@ -144,6 +158,7 @@ export const FeaturesPage = () => {
Show Random Feature
+
{featureState.loading && !loadingRandomFeature && (
Loading Feature
#{featureIndex}...
@@ -151,7 +166,12 @@ export const FeaturesPage = () => {
)}
{featureState.loading && loadingRandomFeature &&
Loading Random Living Feature...
}
{featureState.error &&
Error: {featureState.error.message}
}
- {!featureState.loading && featureState.value &&
}
+ {!featureState.loading && featureState.value && (
+
+
+
+
+ )}
);
From 21f80b7300876f0f1b681af2b999773fc72582ae Mon Sep 17 00:00:00 2001
From: Dest1n1
Date: Mon, 29 Jul 2024 09:32:38 +0800
Subject: [PATCH 11/11] fix(ui): import error
---
ui/src/routes/features/page.tsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ui/src/routes/features/page.tsx b/ui/src/routes/features/page.tsx
index 58102b8..8ea03ee 100644
--- a/ui/src/routes/features/page.tsx
+++ b/ui/src/routes/features/page.tsx
@@ -1,6 +1,6 @@
import { AppNavbar } from "@/components/app/navbar";
import { FeatureCard } from "@/components/feature/feature-card";
-import { SectionNavigator } from "@/components/app/sidenav";
+import { SectionNavigator } from "@/components/app/section-navigator";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";