psiz-org / psiz

A python package for inferring psychological embeddings.
https://psiz.org
Apache License 2.0
31 stars 7 forks source link

Behavior-agnostic `call` method for `PsychologicalEmbedding`. #14

Closed roads closed 2 years ago

roads commented 4 years ago

Current State: Users must implement a subclass of the abstract class PsychologicalEmbedding and implement a behavior-specific model call method.

Desired State: The class PsychologicalEmbedding implements a behavior-agnostic call method. Additionally, it would be desirable if PsychologicalEmbedding could be used directly and all the behavior specific logic was contained in the behavior layer.

If we can implement a generic model call method, there's no need to subclass PsychologicalEmbedding. Although embracing subclassing would future-proof the code to currently unsupported behavior because users could provide their own overriding call method.

Implementing a generic call method that works for Rank, Rate, and Sort behavior is a bit tricky. Different types of behavior require different inputs and different processing rules. But, I think we can exploit tensor dimensions to enable inclusive call semantics.

The Rank model assumes stimulus IDs are passed as inputs to the call method in the format (batch_size, n_ref + 1, n_outcome). The second dimension of the tensor has a length matching the number of stimuli in a trial. For ranked trials this is a query plus the number of references (i.e., n_ref + 1). During the call, it is assumed that the pairwise similarity should be computed between the first element of the 2nd dimension and all other elements (i.e., references).

The call mechanics of Rank trials can be exploited to work for simple Rate trials where there are only two stimuli. However, the input is_select is not relevant. It seems like a bad strategy to have static graphs with unused inputs, but probably not a deal-breaker.

Unfortunately, the call mechanics of Rank trials does not work for Sort trials. The primary issue is that the pairwise similarity must be computed between all stimuli in a trial. When there are only three stimuli, it may be possible to shoe-horned this scenario into Rank call mechanics. For the more general case, a more thoughtful implementation is necessary.

For the time being, I think the best strategy is to use subclassed objects of PsychologicalEmbedding. However, I'll continue to think about solutions for a behavior-agnostic model call method.

roads commented 2 years ago

The PsychologicalEmbedding class has been deprecated. Users should create a model via subclassing or the functional API.