Skip to main content

Weave: labeled_data (23/04/17 22:58:18)

Created on April 17|Last edited on April 17

How do I add computed columns to a wandb Table object?
```python
import wandb

tbl = wandb.Table(columns=["user"])

users = ["geoff", "juergen", "ada"]

[tbl.add_data(user) for user in users]
assert tbl.get_column("user") == users


def get_user_name_length(index, row):
 return {"feature_01": len(row["user"])}


tbl.add_computed_columns(get_user_name_length)
assert tbl.get_column("feature_01") == [5, 7, 3]
```
To add computed columns to a wandb Table object, you can use the `add_computed_columns(func, *columns)` method. Here is an example:

```
import wandb

# Create a wandb Table object
table = wandb.Table(columns=["a", "b", "c"], data=[[1, 2, 3], [4, 5, 6]])

# Define a function that takes an index and row as arguments
def compute_column(index, row):
    return {"d": row["a"] + row["b"] + row["c"]}

# Add a computed column to the table
table.add_computed_columns(compute_column)

# Log the table to wandb
wandb.log({"my_table": table})
```

In this example, the `compute_column` function takes the index and row of each record in the table as arguments and returns a dictionary that maps the new computed column name (in this case, "d") to the computed value. The `add_computed_columns` method applies this function to each row in the table and adds the computed values as a new column. Finally, the table is logged to wandb using the `log` method.

['https://docs.wandb.ai/guides/track/log/log-tables', 'https://docs.wandb.ai/guides/track/log/log-tables', 'https://docs.wandb.ai/ref/python/data-types/table', 'https://docs.wandb.ai/ref/python/public-api/artifact']
[0.31711555, 0.35705897, 0.37264287, 0.3970456]
How can I log a table containing `wandb.Image` objects to WandB?
```python
import numpy as np
import wandb

wandb.init()

tbl = wandb.Table(columns=["image", "label"])

images = np.random.randint(0, 255, [2, 100, 100, 3], dtype=np.uint8)
labels = ["panda", "gibbon"]
[tbl.add_data(wandb.Image(image), label) for image, label in zip(images, labels)]

wandb.log({"classifier_out": tbl})
```
To log a table containing wandb.Image objects to WandB, you should create a `wandb.Table()` object with the corresponding columns and add data to it using the `.add_data()` method. Here is an example:

```python
import wandb

# assume a model has returned predictions on four images
# with the following fields available:
# the image id
# the image pixels, wrapped in a wandb.Image()
# the model's predicted label
# the ground truth label

my_data = [
  [0, wandb.Image("img_0.jpg"), 0, 0],
  [1, wandb.Image("img_1.jpg"), 8, 0],
  [2, wandb.Image("img_2.jpg"), 7, 1],
  [3, wandb.Image("img_3.jpg"), 1, 1]
]

#create a wandb.Table() with corresponding columns
columns=["id", "image", "prediction", "truth"]
test_table = wandb.Table(data=my_data, columns=columns)

# log the table to wandb
wandb.log({"my_table_name": test_table})
```

This will log a table with four rows and four columns to your WandB dashboard.

['https://docs.wandb.ai/guides/track/log/log-tables', 'https://docs.wandb.ai/guides/track/log/media', 'https://docs.wandb.ai/guides/data-vis/tables-quickstart']
[0.1925617, 0.2424692, 0.26168513]
What wandb method can be used to add a column of data to a Table instance?
```python
add_column(
 name, data, optional=(False)
)
```
You can use the `add_column` method to add a new column of data to a Table instance in wandb. Here's an example:

```
import wandb

# Create an empty Table with some columns
table = wandb.Table(columns=["name", "age"])

# Add a new column of data
column_data = ["Alice", "Bob", "Charlie"]
table.add_column(name="city", data=column_data)

# Log the Table to wandb
wandb.log({"my_table": table})
```

['https://docs.wandb.ai/guides/track/log/log-tables', 'https://docs.wandb.ai/guides/track/log/log-tables', 'https://docs.wandb.ai/ref/python/data-types/table']
[0.24121761, 0.32157922, 0.3520938]
QUESTION
ORIGINAL_ANSWER
ORIGINAL_DOC
MODEL_ANSWER
RETRIEVED_DOCS
SIM_SCORES
RETRIEVAL_MATCH
STRING_DIST
MODEL_SCORE
labeler
QUESTION_CORRECT
ORIGINAL_CORRECT
MODEL_CORRECT
MODEL_SCORE_BINARY
HUMAN_SCORE_BINARY
1
2
3
Run: dauntless-frost-41
1

List<File<(table)>>