English 中文(简体)
雪花板ARRAY一栏,作为对雪花园模型的投入。
原标题:Snowflake ARRAY column as input to Snowpark modeling.decomposition

I have a Snowflake table with an ARRAY column containing custom embeddings (with array size>1000). These arrays are sparse, and I would like to reduce their dimension with SVD (or one of the Snowpark ml.modeling.decomposition methods). A toy example of the dataframe would be:

df = session.sql("""
    select  doc1  as doc_id, array_construct(0.1, 0.3, 0.5, 0.7) as doc_vec
    union
    select  doc2  as doc_id, array_construct(0.2, 0.4, 0.6, 0.8) as doc_vec
    """)
print(df)
# DOC_ID  | DOC_VEC
# doc1 | [   0.1,   0.3,   0.5,   0.7 ]
# doc2 | [   0.2,   0.4,   0.6,   0.8 ]

However, when I try to fit this dataframe

from snowflake.ml.modeling.decomposition import TruncatedSVD
tsvd = TruncatedSVD(input_cols =  doc_vec , output_cols= out_svd )
print(tsvd)
out = tsvd.fit(df)

 File "snowflake/ml/modeling/_internal/snowpark_trainer.py", line 218, in fit_wrapper_function
    args = {"X": df[input_cols]}
                 ~~^^^^^^^^^^^^   File "pandas/core/frame.py", line 3767, in __getitem__
    indexer = self.columns._get_indexer_strict(key, "columns")[1]

<...snip...>

KeyError: "None of [Index([ doc_vec ], dtype= object )] are in the [columns]"

Based on the information in this tutorial text_embedding_as_snowpark_python_udf, I suspect the Snowpark array needs to be converted to a np.ndarray before being fed to underlying sklearn.decomposition.TruncatedSVD

难道有人会向我指出,使用Snoflake阵列作为对Snow花园模型的投入的任何例子?

问题回答

现在的问题是,Snowflake目前并不支持零敲碎打的矩阵(但会)。

一名团队撰写了这一样本守则,今后将予以支持:

from snowflake.ml.modeling.decomposition import TruncatedSVD
from snowflake.ml.utils.connection_params import SnowflakeLoginOptions
from snowflake.snowpark import Session, functions as F, types as T

session = Session.builder.configs(SnowflakeLoginOptions()).getOrCreate()

# This can not work right now because snowflake ml doesn t accept input as array type so far... We ll support it in the future!
t = session.range(5).with_column(
    "doc_vec",
    F.array_construct(
        F.lit(0.1),
        F.lit(0.2),
        F.lit(0.3),
    ),
).with_column("doc_vec", F.col("doc_vec").cast(T.ArrayType(T.FloatType())))
tsvd = TruncatedSVD(input_cols="DOC_VEC", output_cols="DOC_VEC")

# create a dataframe as input
t = session.create_dataframe([[0.1, 0.2, 0.3] for _ in range(5)], schema=["A", "B", "C"])
tsvd = TruncatedSVD(input_cols=["A", "B", "C"], output_cols=["OUTPUT"])
t.show()

tsvd.fit(t)
# show the results
tsvd.transform(t).show()




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签