noahsettersten
commited on
Commit
•
58815a9
1
Parent(s):
37dc524
feat: Store vector for text in feedback, associate to code_vectors
Browse files- lib/medical_transcription/code_feedback.ex +5 -4
- lib/medical_transcription/code_searcher.ex +0 -4
- lib/medical_transcription_web/components/components.ex +3 -4
- lib/medical_transcription_web/components/transcription_text_component.ex +3 -3
- lib/medical_transcription_web/live/home_live/index.ex +6 -5
- priv/repo/migrations/20240125172837_migrate_to_vector_for_code_feedbacks.exs +14 -0
lib/medical_transcription/code_feedback.ex
CHANGED
@@ -6,15 +6,16 @@ defmodule MedicalTranscription.CodeFeedback do
|
|
6 |
|
7 |
schema "code_feedbacks" do
|
8 |
field :text, :string
|
9 |
-
field :
|
10 |
-
field :long_description, :string
|
11 |
field :response, :boolean
|
|
|
|
|
12 |
end
|
13 |
|
14 |
def changeset(code_feedback, params \\ %{}) do
|
15 |
code_feedback
|
16 |
-
|> Ecto.Changeset.cast(params, [:text, :
|
17 |
-
|> Ecto.Changeset.validate_required([:text, :
|
18 |
end
|
19 |
|
20 |
def track_response(params) do
|
|
|
6 |
|
7 |
schema "code_feedbacks" do
|
8 |
field :text, :string
|
9 |
+
field :text_vector, Pgvector.Ecto.Vector
|
|
|
10 |
field :response, :boolean
|
11 |
+
|
12 |
+
belongs_to :code_vector, MedicalTranscription.CodeVector
|
13 |
end
|
14 |
|
15 |
def changeset(code_feedback, params \\ %{}) do
|
16 |
code_feedback
|
17 |
+
|> Ecto.Changeset.cast(params, [:text, :text_vector, :response, :code_vector_id])
|
18 |
+
|> Ecto.Changeset.validate_required([:text, :text_vector, :response, :code_vector_id])
|
19 |
end
|
20 |
|
21 |
def track_response(params) do
|
lib/medical_transcription/code_searcher.ex
CHANGED
@@ -5,13 +5,9 @@ defmodule MedicalTranscription.CodeSearcher do
|
|
5 |
"""
|
6 |
|
7 |
alias MedicalTranscription.CodeVector
|
8 |
-
alias AudioTagger.Structs.TagResult
|
9 |
|
10 |
def process_chunk(model_tuple, text) do
|
11 |
search_for_similar_codes(model_tuple, text)
|
12 |
-
|> Enum.map(fn %CodeVector{code: code, description: description} ->
|
13 |
-
%TagResult{code: code, label: description, score: 1.0}
|
14 |
-
end)
|
15 |
|
16 |
# -- Remove matches that don't exceed a given threshold
|
17 |
# TODO: This depends on receiving a similarity score from the Postgres query
|
|
|
5 |
"""
|
6 |
|
7 |
alias MedicalTranscription.CodeVector
|
|
|
8 |
|
9 |
def process_chunk(model_tuple, text) do
|
10 |
search_for_similar_codes(model_tuple, text)
|
|
|
|
|
|
|
11 |
|
12 |
# -- Remove matches that don't exceed a given threshold
|
13 |
# TODO: This depends on receiving a similarity score from the Postgres query
|
lib/medical_transcription_web/components/components.ex
CHANGED
@@ -123,8 +123,8 @@ defmodule MedicalTranscriptionWeb.Components do
|
|
123 |
~H"""
|
124 |
<div class="flex items-center gap-4 px-[14px] py-3 text-sm">
|
125 |
<div class="flex gap-3">
|
126 |
-
<.feedback_button
|
127 |
-
<.feedback_button
|
128 |
</div>
|
129 |
|
130 |
<div
|
@@ -142,9 +142,8 @@ defmodule MedicalTranscriptionWeb.Components do
|
|
142 |
~H"""
|
143 |
<button
|
144 |
phx-click="add_feedback"
|
145 |
-
phx-value-
|
146 |
phx-value-text={@text}
|
147 |
-
phx-value-long-description={@label}
|
148 |
phx-value-response={@response}
|
149 |
type="button"
|
150 |
class="p-2 border border-button-deactivated-background rounded-lg hover:bg-slate-200"
|
|
|
123 |
~H"""
|
124 |
<div class="flex items-center gap-4 px-[14px] py-3 text-sm">
|
125 |
<div class="flex gap-3">
|
126 |
+
<.feedback_button code_vector_id={@code_vector_id} text={@text} response="true" />
|
127 |
+
<.feedback_button code_vector_id={@code_vector_id} text={@text} response="false" />
|
128 |
</div>
|
129 |
|
130 |
<div
|
|
|
142 |
~H"""
|
143 |
<button
|
144 |
phx-click="add_feedback"
|
145 |
+
phx-value-code_vector_id={@code_vector_id}
|
146 |
phx-value-text={@text}
|
|
|
147 |
phx-value-response={@response}
|
148 |
type="button"
|
149 |
class="p-2 border border-button-deactivated-background rounded-lg hover:bg-slate-200"
|
lib/medical_transcription_web/components/transcription_text_component.ex
CHANGED
@@ -6,7 +6,7 @@ defmodule MedicalTranscriptionWeb.Components.TranscriptionTextComponent do
|
|
6 |
use MedicalTranscriptionWeb, :live_component
|
7 |
import MedicalTranscriptionWeb.Components
|
8 |
import MedicalTranscriptionWeb.Components.KeywordHighlighter
|
9 |
-
alias
|
10 |
|
11 |
@impl Phoenix.LiveComponent
|
12 |
def update(assigns, socket) do
|
@@ -53,8 +53,8 @@ defmodule MedicalTranscriptionWeb.Components.TranscriptionTextComponent do
|
|
53 |
</div>
|
54 |
|
55 |
<div class="flex-1 flex flex-col items-stretch gap-3">
|
56 |
-
<%= for %
|
57 |
-
<.tag_result code={code} label={label} score={
|
58 |
<% end %>
|
59 |
</div>
|
60 |
</div>
|
|
|
6 |
use MedicalTranscriptionWeb, :live_component
|
7 |
import MedicalTranscriptionWeb.Components
|
8 |
import MedicalTranscriptionWeb.Components.KeywordHighlighter
|
9 |
+
alias MedicalTranscription.CodeVector
|
10 |
|
11 |
@impl Phoenix.LiveComponent
|
12 |
def update(assigns, socket) do
|
|
|
53 |
</div>
|
54 |
|
55 |
<div class="flex-1 flex flex-col items-stretch gap-3">
|
56 |
+
<%= for %CodeVector{id: id, code: code, description: label} <- @row.tags do %>
|
57 |
+
<.tag_result code_vector_id={id} code={code} label={label} score={1.0} text={@row.text} />
|
58 |
<% end %>
|
59 |
</div>
|
60 |
</div>
|
lib/medical_transcription_web/live/home_live/index.ex
CHANGED
@@ -81,12 +81,13 @@ defmodule MedicalTranscriptionWeb.HomeLive.Index do
|
|
81 |
|
82 |
@impl true
|
83 |
def handle_event("add_feedback", params, socket) do
|
84 |
-
|
85 |
-
params
|
86 |
-
|> Map.put("long_description", params["long-description"])
|
87 |
-
|> Map.drop(["long-description"])
|
88 |
|
89 |
-
result =
|
|
|
|
|
|
|
90 |
|
91 |
socket =
|
92 |
case result do
|
|
|
81 |
|
82 |
@impl true
|
83 |
def handle_event("add_feedback", params, socket) do
|
84 |
+
text_vector =
|
85 |
+
AudioTagger.Vectors.embed([params["text"]]) |> Map.get(:pooled_state) |> Nx.to_flat_list()
|
|
|
|
|
86 |
|
87 |
+
result =
|
88 |
+
params
|
89 |
+
|> Map.put("text_vector", text_vector)
|
90 |
+
|> MedicalTranscription.CodeFeedback.track_response()
|
91 |
|
92 |
socket =
|
93 |
case result do
|
priv/repo/migrations/20240125172837_migrate_to_vector_for_code_feedbacks.exs
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
defmodule MedicalTranscription.Repo.Migrations.MigrateToVectorForCodeFeedbacks do
|
2 |
+
use Ecto.Migration
|
3 |
+
|
4 |
+
def change do
|
5 |
+
alter table("code_feedbacks") do
|
6 |
+
add :text_vector, :vector, size: 384
|
7 |
+
add :code_vector_id, references("code_vectors")
|
8 |
+
|
9 |
+
# These two columns can be found on the `code_vectors` table referenced above
|
10 |
+
remove :code, :string
|
11 |
+
remove :long_description, :string
|
12 |
+
end
|
13 |
+
end
|
14 |
+
end
|