Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
kduxin committed Nov 7, 2022
1 parent 92b1d93 commit 1a73200
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,44 +218,35 @@ In FIRE, the `slicing` and similarity computation are done in a similar way to v

- Slicing:
```python
funcs1, measures1 = model[["apple", "pear", ...]] # (n1, D)
funcs2, measures2 = model[["iphone", "fruit", ...]] # (n1, D)
x1 = model[["apple", "pear", ...]] # FIRETensor: (n1, D)
x2 = model[["iphone", "fruit", ...]] # FIRETensor: (n1, D)
```
- Computation of paired similarity (where n1 == n2):
```python
sim = measures2.integral(funcs1) # (n1,)
+ measures1.integral(funcs2) # (n2,)
sim = x2.measures.integral(x1.funcs) # (n1,)
+ x1.measures.integral(x2.funcs) # (n2,)
```
- Computation of cross similarity:
```python
sim = measures2.integral(funcs1, cross=True) # (n1, n2)
+ measures1.integral(funcs2, cross=True).T # (n2, n1) -> transpose -> (n1, n2)
sim = x2.measures.integral(x1.funcs, cross=True) # (n1, n2)
+ x1.measures.integral(x2.funcs, cross=True).T # (n2, n1) -> transpose -> (n1, n2)
```

In addition to the way above where `integral` must be explicitly invoked,
a more friendly way is also provided, as below:
```python
# paired similarity
# sim: (n1,)
sim = (funcs1 * measures2) # (n1, K) where K is the number of locations in the measure
.sum(-1)
+ (measures1 * funcs2) # (n2, K)
.sum(-1)
sim = x1.funcs * x2.measures # (n1,)
+ x1.measures * x2.funcs # (n2,)

# cross similarity
sim = funcs1 @ measures2 + measures1 @ funcs2 # (n1, n2)
sim = x1.funcs @ x2.measures + x1.measures @ x2.funcs # (n1, n2)
```

Furthermore, the two steps above can be done in one line:
```python
sim = model[["apple", "pear", "melon"]] @ model[["iphone", "fruit"]] # (3, 2)

# which is equivalent to below:
# slice1 = model[["apple", "pear", "melon"]]
# slice2 = model[["iphone", "fruit"]]
# funcs1, measures1 = slice1
# funcs2, measures2 = slice2
# sim = measures2.integral(funcs1, cross=True) + measures1.integral(funcs2, cross=True).T
```


Expand All @@ -270,16 +261,16 @@ $$ \text{sim}(w_i,w_j) \leftarrow \text{sim}(w_i,w_j) - \int f_i ~\mathrm{d}\mu_
is done by:

```python
funcs1, measures1 = [["apple", "pear"]]
funcs2, measures2 = [["fruit", "iphone"]]
sim_reg = measures2.integral(funcs1) + measures1.integral(funcs2) \
- measures1.integral(funcs1) - measures2.integral(funcs2)
x1 = model[["apple", "pear"]]
x2 = model[["fruit", "iphone"]]
sim_reg = x2.measures.integral(x1.funcs) + x1.measures.integral(x2.funcs) \
- x1.measures.integral(x1.funcs) - x2.measures.integral(x1.funcs)
```
or equivalently:
```python
sim_reg = ((funcs2 - funcs1) * measures1 + (funcs1 - funcs2) * measures2).sum(-1)
sim_reg = (x2.funcs - x1.funcs) * x1.measures + (x1.funcs - x2.funcs) * x2.measures
```
where `funcs2 - funcs1` produces a new functional.
where `x2.funcs - x1.funcs` produces a new functional.



Expand Down

0 comments on commit 1a73200

Please sign in to comment.