Pupil dilation is a reflection of sympathetic arousal, and it seems to be related specifically to prediction error (Braem et al., 2015; Lavin et al., 2013; Preuschoff et al., 2011) and consequently predicts your learning rate (Nassar et al., 2012).
In the case where you see an attractive person amidst a sea of average faces, this violates your predictions--you have prediction error (or "surprise"). You expected to see an average face, not an attractive face, and your pupils dilate in response. If you are continually exposed to this attractive person, your pupil dilation will decrease over time.
This is true with emotions more generally--when you feel negative or positive this usually indicates prediction error (or success), which then up- or downregulates your learning rate, respectively (e.g., Joffily & Coricelli, 2013).
Why is pupil dilation associated with prediction error? The sphincter (contracts the eye) and dilator (dilates the eye) are innervated by acetylcholine and noradrenaline, respectively. Noradrenergic activity in the locus coeruleus might encode "unexpected uncertainty," which interacts with antagonistic cholinergic activity. Interestingly, dilating the pupil on one task can increase the learning rate on another, unrelated task (Nassar et al., 2012), which might be mediated by incidental activation of noradrenergic activity in the locus coeruleus.
Hmmmm, I don't actually seem to know enough about this such that I can explain all of it clearly! But hopefully this provides some insight into your question.