Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions bigframes/operations/semantics.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,13 +807,17 @@ def top_k(
>>> import bigframes.ml.llm as llm
>>> model = llm.GeminiTextGenerator(model_name="gemini-1.5-flash-001")

>>> df = bpd.DataFrame({"Animals": ["Dog", "Bird", "Cat", "Horse"]})
>>> df = bpd.DataFrame(
... {
... "Animals": ["Dog", "Bird", "Cat", "Horse"],
... "Sounds": ["Woof", "Chirp", "Meow", "Neigh"],
... })
>>> df.semantics.top_k("{Animals} are more popular as pets", model=model, k=2)
Animals
0 Dog
2 Cat
Animals Sounds
0 Dog Woof
2 Cat Meow
<BLANKLINE>
[2 rows x 1 columns]
[2 rows x 2 columns]

Args:
instruction (str):
Expand Down Expand Up @@ -911,14 +915,8 @@ def top_k(
)
num_selected += num_new_selected

df = (
df[df[status_column] > 0]
.drop(["index", status_column], axis=1)
.rename(columns={"old_index": "index"})
.set_index("index")
)
df.index.name = None
return df
result_df: bigframes.dataframe.DataFrame = self._df.copy()
return result_df[df.set_index("old_index")[status_column] > 0.0]

@staticmethod
def _topk_partition(
Expand Down